[−][src]Function tweetr::util::prompt_nonzero_len
pub fn prompt_nonzero_len<R, W, F>(
input: &mut R,
output: &mut W,
prompt_s: &str,
verifier: F
) -> IoResult<String> where
R: BufRead,
W: Write,
F: Fn(&String) -> bool,
Ask the user to input a string of non-zero length, (re)prompting as necessary.
Examples
Allow anything as long as it's something:
assert_eq!(prompt_nonzero_len(&mut Cursor::new(b"123456789"), &mut Vec::new(), "Allowed chars", |_| true).unwrap(), "123456789".to_string());
Allow valid u64
s:
assert_eq!(prompt_nonzero_len(&mut Cursor::new(b"123456789"), &mut Vec::new(), "Number", |s| u64::from_str(s).is_ok()).unwrap(), "123456789".to_string()); assert!(prompt_nonzero_len(&mut Cursor::new(b"123abcdef"), &mut Vec::new(), "Number", |s| u64::from_str(s).is_ok()).is_err());