InputBuild

Trait InputBuild 

Source
pub trait InputBuild<T: FromStr> {
    // Required methods
    fn msg(self, msg: impl ToString) -> Self;
    fn repeat_msg(self, msg: impl ToString) -> Self;
    fn err(self, err: impl ToString) -> Self;
    fn add_test<F: Fn(&T) -> bool + 'static>(self, test: F) -> Self;
    fn add_err_test<F>(self, test: F, err: impl ToString) -> Self
       where F: Fn(&T) -> bool + 'static;
    fn clear_tests(self) -> Self;
    fn err_match<F>(self, err_match: F) -> Self
       where F: Fn(&T::Err) -> Option<String> + 'static;
    fn inside<U: InsideFunc<T>>(self, constraint: U) -> Self;
    fn inside_err<U: InsideFunc<T>>(
        self,
        constraint: U,
        err: impl ToString,
    ) -> Self;
    fn toggle_msg_repeat(self) -> Self;
    fn prompting_on(self, prompt_output: RefCell<Box<dyn Write>>) -> Self;
    fn prompting_on_stderr(self) -> Self;
}
Expand description

Trait for common types that store input settings.

Required Methods§

Source

fn msg(self, msg: impl ToString) -> Self

Changes or adds a prompt message that gets printed once when input if fetched.

Source

fn repeat_msg(self, msg: impl ToString) -> Self

Changes or adds a prompt message and that is repeated each time input is requested.

Source

fn err(self, err: impl ToString) -> Self

Changes fallback error message.

Source

fn add_test<F: Fn(&T) -> bool + 'static>(self, test: F) -> Self

Adds a validation check on input.

Source

fn add_err_test<F>(self, test: F, err: impl ToString) -> Self
where F: Fn(&T) -> bool + 'static,

Adds a validation check on input with a custom error message printed when the test fails.

Source

fn clear_tests(self) -> Self

Removes all validation checks made by .add_test(), .add_err_test(), .inside() and .inside_err().

Source

fn err_match<F>(self, err_match: F) -> Self
where F: Fn(&T::Err) -> Option<String> + 'static,

Used specify custom error messages that depend on the errors produced by from_str().

Source

fn inside<U: InsideFunc<T>>(self, constraint: U) -> Self

Ensures that input is within a range, array or vector.

Source

fn inside_err<U: InsideFunc<T>>(self, constraint: U, err: impl ToString) -> Self

Ensures that input is within a range, array or vector with a custom error message printed when input fails.

Source

fn toggle_msg_repeat(self) -> Self

Toggles whether a prompt message gets printed once or each time input is requested.

Source

fn prompting_on(self, prompt_output: RefCell<Box<dyn Write>>) -> Self

Send prompts to custom writer instead of stdout

Source

fn prompting_on_stderr(self) -> Self

Send prompts to stderr instead of stdout

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§