[][src]Macro rubric::prompt

macro_rules! prompt {
    ( $msg:expr, $type:ty ) => { ... };
}

Calls prompt, then tries to parse the input into the provided type. If parsing fails, it will try again.

This method trims whitespace on the beginning and end of the input string.

Example

#[macro_use] extern crate rubric;
use rubric::helpers;
use std::net::Ipv4Addr;

fn main() {
    let string = prompt!("Enter a string: ", String);
    println!("{}", string);

    let number = prompt!("Enter a number: ", u32);
    println!("{}", number);

    let another = prompt!("Enter an IP: ", Ipv4Addr);
    println!("{}", another);
}

They input:

Enter a string: Here's a string
Here's a string
Enter a number: 123
123
Enter an IP: not an IP
Could not parse input. Try again.
Enter an IP: 192.168.0.1
192.168.0.1