Struct Input

Source
pub struct Input(/* private fields */);
Expand description

A prompt that asks the user to enter text input

Implementations§

Source§

impl Input

Source

pub fn new() -> Result<Self, InteractionError>

Create the prompt, returning an error if interactive context is incorrectly set.

Source

pub fn set_prompt(&mut self, prompt: String)

Set the prompt.

Source

pub fn with_prompt<S: ToString>(&mut self, prompt: S) -> &mut Self

Builder pattern for Self::set_prompt

Source

pub fn interact(&mut self) -> Result<String, InteractionError>

Present the prompt to the user. May return an error if in a non-interactive context, or interaction fails for any other reason

Source§

impl Input

Source

pub fn set_default(&mut self, value: String)

Set the default selection. If the user does not input anything, this value will be used instead.

Source

pub fn with_default<I: Into<String>>(&mut self, value: I) -> &mut Self

Builder pattern for Self::set_default

Source§

impl Input

Source

pub fn set_allow_empty(&mut self, empty: bool)

Sets if no input is a valid input. Default: false.

Source

pub fn with_allow_empty(&mut self, empty: bool) -> &mut Self

Builder pattern for Self::set_allow_empty

Source

pub fn set_validator<V, E>(&mut self, validator: V)
where V: Fn(&String) -> Result<(), E> + 'static, E: ToString,

Set a validator to be run on input. If the validator returns Ok, the input will be deemed valid. If the validator returns Err, the prompt will display the error message

Source

pub fn with_validator<V, E>(&mut self, validator: V) -> &mut Self
where V: Fn(&String) -> Result<(), E> + 'static, E: ToString,

Builder pattern for Self::set_validator

Source§

impl Input

Source

pub fn set_inital_text<S: ToString>(&mut self, text: S)

Source

pub fn with_initial_text<S: ToString>(&mut self, text: S) -> &mut Self

Auto Trait Implementations§

§

impl Freeze for Input

§

impl !RefUnwindSafe for Input

§

impl !Send for Input

§

impl !Sync for Input

§

impl Unpin for Input

§

impl !UnwindSafe for Input

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> 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, 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.