use std::io::{Read, Write}; use IntoRawMode; /// Extension to `Read` trait. pub trait ReadExt { /// Read a password. fn read_passwd(&mut self, writer: &mut W) -> Option; } impl ReadExt for R { fn read_passwd(&mut self, writer: &mut W) -> Option { let _raw = if let Ok(x) = writer.into_raw_mode() { x } else { return None; }; let mut string = String::with_capacity(30); for c in self.chars() { match if let Ok(c) = c { c } else { return None; } { '\x00' | '\x03' | '\x04' => return None, '\r' => return Some(string), b => string.push(b), } } Some(string) } }