[−][src]Struct casual::Input
An input builder.
Implementations
impl<T> Input<T>
[src]
pub fn new() -> Self
[src]
Construct a new empty Input
.
pub fn prompt<S>(self, prompt: S) -> Self where
S: Into<String>,
[src]
S: Into<String>,
Set the prompt to display before waiting for user input.
pub fn default(self, default: T) -> Self
[src]
Set the default value.
If set, this will be returned in the event the user enters an empty input.
pub fn matches<F>(self, matches: F) -> Self where
F: Fn(&T) -> bool + 'static,
[src]
F: Fn(&T) -> bool + 'static,
Check input values.
If set, this function will be called on the parsed user input and only if it passes will we return the value.
Examples
ⓘThis example is not tested
let num: u32 = Input::new().matches(|x| *x != 10).get()
impl<T> Input<T> where
T: FromStr,
<T as FromStr>::Err: Display,
[src]
T: FromStr,
<T as FromStr>::Err: Display,
pub fn get(self) -> T
[src]
Consumes the Input
and reads the input from the user.
This function uses FromStr
to parse the input data.
pub fn check<F>(self, check: F) -> bool where
F: Fn(T) -> bool,
[src]
F: Fn(T) -> bool,
Consumes the Input
and checks the result.
This function uses FromStr
to parse the input data. The result is
then fed to the given closure.
Trait Implementations
Auto Trait Implementations
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,
T: Unpin,
impl<T> !UnwindSafe for Input<T>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,