pub struct Input<T> { /* private fields */ }
Expand description
An input builder.
Implementations§
Source§impl<T> Input<T>
impl<T> Input<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Construct a new empty Input
.
Identical to Input::default()
.
Sourcepub fn prompt<S: Into<String>>(self, prompt: S) -> Self
pub fn prompt<S: Into<String>>(self, prompt: S) -> Self
Set the prompt to display before waiting for user input.
Source§impl<T> Input<T>
impl<T> Input<T>
Sourcepub fn get(self) -> T
pub fn get(self) -> T
Consumes the Input
and reads the input from the user.
This function uses FromStr
to parse the input data.
let num: u32 = Input::new().prompt("Enter a number: ").get();
Examples found in repository?
examples/guessing_game.rs (line 19)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
fn main() {
let mut num = random();
println!("Try guess the number I am thinking of 😃 ...");
println!(" (hint: it's between 0 and 255)\n");
loop {
let guess: u32 = casual::prompt("Enter your guess: ").get();
if guess < num {
println!("Too low!");
} else if guess > num {
println!("Too high!");
} else {
println!("You got it!");
println!("The number was: {}\n", num);
if casual::confirm("Do you want to play again?") {
num = random();
} else {
break;
}
}
}
}
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Input<T>where
T: Freeze,
impl<T> !RefUnwindSafe for Input<T>
impl<T> !Send for Input<T>
impl<T> !Sync for Input<T>
impl<T> Unpin for Input<T>where
T: Unpin,
impl<T> !UnwindSafe for Input<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more