InputBuilderOnce

Struct InputBuilderOnce 

Source
pub struct InputBuilderOnce<T: FromStr> { /* private fields */ }
Expand description

‘builder’ used to store the settings that are used to fetch input.

.get() method takes ownership of the settings so can be called only once without cloning.

This type has support for default input value.

Implementations§

Source§

impl<T: FromStr> InputBuilderOnce<T>

Source

pub fn get(self) -> T

‘gets’ the input form the user.

Panics if unable to read input line.

Source

pub fn try_get(self) -> Result<T>

‘gets’ the input form the user.

§Errors

Returns Err if unable to read input line.

Trait Implementations§

Source§

impl<T> Clone for InputBuilderOnce<T>
where T: Clone + FromStr,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: FromStr> InputBuild<T> for InputBuilderOnce<T>

Source§

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

Changes or adds a prompt message that gets printed once when input if fetched. Read more
Source§

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

Changes or adds a prompt message and that is repeated each time input is requested. Read more
Source§

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

Changes fallback error message. Read more
Source§

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

Adds a validation check on input to ensure the value meets your criteria. Read more
Source§

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

Does the same thing as InputBuild::err, but with a custom error message printed when the test fails. Read more
Source§

fn clear_tests(self) -> Self

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 FromStr. Read more
Source§

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

Ensures that input is within a range, array or vector. Read more
Source§

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

Does the same thing as InputBuild::inside, but 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
Source§

impl<T: FromStr + PartialOrd + 'static> InputConstraints<T> for InputBuilderOnce<T>

Source§

fn min(self, min: T) -> Self

Sets a minimum input value.
Source§

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

Sets a minimum input value with custom error message.
Source§

fn max(self, max: T) -> Self

Sets a maximum input value.
Source§

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

Sets a maximum input value with custom error message.
Source§

fn min_max(self, min: T, max: T) -> Self

Sets a minimum and maximum input value.
Source§

fn min_max_err(self, min: T, max: T, err: impl ToString) -> Self

Sets a minimum and maximum input value with custom error message.
Source§

fn not(self, this: T) -> Self

Sets a restricted input value.
Source§

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

Sets a restricted input value with custom error message.

Auto Trait Implementations§

§

impl<T> !Freeze for InputBuilderOnce<T>

§

impl<T> !RefUnwindSafe for InputBuilderOnce<T>

§

impl<T> !Send for InputBuilderOnce<T>

§

impl<T> !Sync for InputBuilderOnce<T>

§

impl<T> Unpin for InputBuilderOnce<T>
where T: Unpin,

§

impl<T> !UnwindSafe for InputBuilderOnce<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.