[][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.

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]

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]

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]

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

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.