read_stdin

Function read_stdin 

Source
pub fn read_stdin() -> Result<String, Error>
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		let prompt = prompt.unwrap_or_else(
23			|| format!("Enter a password (must have {}+ characters and have {}+ digits): ", self.min_len, self.min_digits)
24		);
25		loop {
26			
27			// you could also do `let password = try_prompt!(prompt)?;`
28			print!("{prompt}");
29			let password = read_stdin()?;
30			
31			if password.len() < 10 {
32				println!("Invalid, password must have at least 10 characters");
33				continue;
34			}
35			if password.chars().filter(|c| c.is_digit(10)).count() < 1 {
36				println!("Invalid, password must have at least 1 digit");
37				continue;
38			}
39			
40			return Ok(password)
41			
42		}
43	}