[][src]Function tweetr::util::prompt_any_len

pub fn prompt_any_len<R, W, F>(
    input: &mut R,
    output: &mut W,
    prompt_s: &str,
    verifier: F
) -> IoResult<Option<String>> where
    R: BufRead,
    W: Write,
    F: Fn(&String) -> bool

Ask the user to input a string of any length after printing a prompt prompting.

Will return None if the string is empty.

Examples

Allow anything:

assert_eq!(prompt_any_len(&mut Cursor::new(b"123456789"),
                          &mut Vec::new(),
                          "Allowed chars",
                          |_| true).unwrap().unwrap(),
           "123456789".to_string());
assert_eq!(prompt_any_len(&mut Cursor::new(b""),
                          &mut Vec::new(),
                          "Allowed chars",
                          |_| true).unwrap(),
           None);

Allow valid u64s:

assert_eq!(prompt_any_len(&mut Cursor::new(b"123456789"),
                          &mut Vec::new(),
                          "Number",
                          |s| u64::from_str(s).is_ok()).unwrap().unwrap(),
           "123456789".to_string());
assert_eq!(prompt_any_len(&mut Cursor::new(b"123abcdef"),
                          &mut Vec::new(),
                          "Number",
                          |s| u64::from_str(s).is_ok()).map_err(|_| ()),
           Ok(None));