[go: up one dir, main page]

Trait TermRead

Source
pub trait TermRead {
    // Required methods
    fn events(self) -> Events<Self> 
       where Self: Sized;
    fn keys(self) -> Keys<Self> 
       where Self: Sized;
    fn read_line(&mut self) -> Result<Option<String>>;

    // Provided method
    fn read_passwd<W: Write + AsFd>(
        &mut self,
        writer: &mut W,
    ) -> Result<Option<String>> { ... }
}
Expand description

Extension to Read trait.

Required Methods§

Source

fn events(self) -> Events<Self>
where Self: Sized,

An iterator over input events.

Source

fn keys(self) -> Keys<Self>
where Self: Sized,

An iterator over key inputs.

Source

fn read_line(&mut self) -> Result<Option<String>>

Read a line.

EOT and ETX will abort the prompt, returning None. Newline or carriage return will complete the input.

Provided Methods§

Source

fn read_passwd<W: Write + AsFd>( &mut self, writer: &mut W, ) -> Result<Option<String>>

Read a password.

EOT and ETX will abort the prompt, returning None. Newline or carriage return will complete the input.

Examples found in repository?
examples/read.rs (line 15)
6fn main() {
7    let stdout = stdout();
8    let mut stdout = stdout.lock();
9    let stdin = stdin();
10    let mut stdin = stdin.lock();
11
12    stdout.write_all(b"password: ").unwrap();
13    stdout.flush().unwrap();
14
15    let pass = stdin.read_passwd(&mut stdout);
16
17    if let Ok(Some(pass)) = pass {
18        stdout.write_all(pass.as_bytes()).unwrap();
19        stdout.write_all(b"\n").unwrap();
20    } else {
21        stdout.write_all(b"Error\n").unwrap();
22    }
23}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§