Trait termion::input::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)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
fn main() {
    let stdout = stdout();
    let mut stdout = stdout.lock();
    let stdin = stdin();
    let mut stdin = stdin.lock();

    stdout.write_all(b"password: ").unwrap();
    stdout.flush().unwrap();

    let pass = stdin.read_passwd(&mut stdout);

    if let Ok(Some(pass)) = pass {
        stdout.write_all(pass.as_bytes()).unwrap();
        stdout.write_all(b"\n").unwrap();
    } else {
        stdout.write_all(b"Error\n").unwrap();
    }
}

Object Safety§

This trait is not object safe.

Implementors§