[][src]Struct casual::Input

pub struct Input<T> { /* fields omitted */ }

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]

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]

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]

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]

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

impl<T> Debug for Input<T> where
    T: Debug
[src]

impl<T> Default for Input<T>[src]

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

impl<T> !UnwindSafe for Input<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.