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)
13fn main() {
14 let mut num = random();
15 println!("Try guess the number I am thinking of 😃 ...");
16 println!(" (hint: it's between 0 and 255)\n");
17
18 loop {
19 let guess: u32 = casual::prompt("Enter your guess: ").get();
20
21 if guess < num {
22 println!("Too low!");
23 } else if guess > num {
24 println!("Too high!");
25 } else {
26 println!("You got it!");
27 println!("The number was: {}\n", num);
28
29 if casual::confirm("Do you want to play again?") {
30 num = random();
31 } else {
32 break;
33 }
34 }
35 }
36}
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