pub fn read_stdin() -> BoxResult<String>Expand description
Utility function, mostly for internal use
Examples found in repository?
examples/custom_tryread.rs (line 29)
21 fn try_read_line(self, prompt: Option<String>, default: Option<Self::Default>) -> smart_read::BoxResult<Self::Output> {
22 if default.is_some() {return DefaultNotAllowedError::new_box_result();}
23 let prompt = prompt.unwrap_or_else(
24 || format!("Enter a password (must have {}+ characters and have {}+ digits): ", self.min_len, self.min_digits)
25 );
26 loop {
27
28 print!("{prompt}");
29 let password = read_stdin()?;
30
31 if password.len() < 10 {
32 println!("Password must have at least 10 characters");
33 continue;
34 }
35 if password.chars().filter(|c| c.is_digit(10)).count() < 1 {
36 println!("Password must have at least 1 digit");
37 continue;
38 }
39
40 return Ok(password)
41
42 }
43 }