[−][src]Struct casual::Input
An input builder.
Implementations
impl<T> Input<T>
[src]
pub fn new() -> Self
[src]
Construct a new empty Input
.
Identical to Input::default()
.
pub fn prompt<S: Into<String>>(self, prompt: S) -> Self
[src]
Set the prompt to display before waiting for user input.
pub fn prefix<S: Into<String>>(self, prefix: S) -> Self
[src]
Set the prompt prefix.
pub fn suffix<S: Into<String>>(self, suffix: S) -> Self
[src]
Set the prompt suffix.
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
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.
let num: u32 = Input::new().prompt("Enter a number: ").get();
pub fn map<F, U>(self, map: F) -> U where
F: Fn(T) -> U,
[src]
F: Fn(T) -> U,
Consumes the Input
and applies the given function to it.
This function uses FromStr
to parse the input data. The result is
then fed to the given closure.
let value = Input::new().map(|s: String| &s.to_lowercase() == "yes");
Trait Implementations
impl<T: Debug> Debug for Input<T>
[src]
impl<T> Default for Input<T>
[src]
fn default() -> Self
[src]
Construct a new empty Input
.
Identical to Input::new()
.
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>,