[−][src]Struct coreutils_core::input::Input
The Input struct handles issuing messages and getting responses from the user.
Example
To ask the user whether they want to make a change or not, and validate their response
into a bool
, the Input
struct can be used like so:
ⓘThis example is not tested
let answer: bool = Input::new() .with_msg("Do you want to make this change?") .with_err_msg("Error! Failure to read!") .is_affirmative(); assert_eq!(answer, true);
One could also get the response directly from the user like so:
ⓘThis example is not tested
let answer: String = Input::new() .with_msg("Do you want to make this change?") .with_err_msg("Error! Failure to read!") .get(); assert_eq!(answer, String::from("Yes, I do"));
Methods
impl<'a> Input<'a>
[src]
pub const fn new() -> Self
[src]
Initializes a new Input builder.
pub fn with_msg(&mut self, msg: &'a str) -> &mut Self
[src]
Specifies the message to display to the user.
pub fn with_err_msg(&mut self, err_msg: &'a str) -> &mut Self
[src]
Specifies the error message to display to the user. NOTE: This error message prepends the actual error message produced.
pub fn get(&self) -> Option<String>
[src]
Gets the input value the user entered as a String
.
pub fn is_affirmative(&self) -> bool
[src]
Verifies whether the user input is considered an 'affirmative' answer.
Trait Implementations
impl<'a> Clone for Input<'a>
[src]
impl<'a> Debug for Input<'a>
[src]
impl<'a> Default for Input<'a>
[src]
Auto Trait Implementations
impl<'a> RefUnwindSafe for Input<'a>
impl<'a> Send for Input<'a>
impl<'a> Sync for Input<'a>
impl<'a> Unpin for Input<'a>
impl<'a> UnwindSafe for Input<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,