InputBuilder

Struct InputBuilder 

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

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

.get() method only takes these settings by reference so can be called multiple times.

This type does not have support for default input value.

Implementations§

Source§

impl<T: FromStr> InputBuilder<T>

Source

pub fn new() -> Self

Creates a new instance of InputBuilder with default settings.

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.

Source

pub fn default(self, default: T) -> InputBuilderOnce<T>

Changes or adds a default input value.

Trait Implementations§

Source§

impl<T: FromStr + Clone> Clone for InputBuilder<T>

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> Default for InputBuilder<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

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

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
Source§

impl<T: FromStr + PartialOrd + 'static> InputConstraints<T> for InputBuilder<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 InputBuilder<T>

§

impl<T> !RefUnwindSafe for InputBuilder<T>

§

impl<T> !Send for InputBuilder<T>

§

impl<T> !Sync for InputBuilder<T>

§

impl<T> Unpin for InputBuilder<T>

§

impl<T> !UnwindSafe for InputBuilder<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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<T> ErasedDestructor for T
where T: 'static,