Skip to main content

Input

Struct Input 

Source
pub struct Input<'a> { /* private fields */ }
Expand description

Builder for configuring and reading user input

Provides a fluent API for combining options like default values, trimming behavior, and prompt visibility.

§Examples

use input_py::Input;

// Basic usage
let name = Input::new("Enter your name").read().unwrap();

// With default value and no trimming
let port = Input::new("Enter port")
    .default("8080")
    .trim(false)
    .read()
    .unwrap();

Implementations§

Source§

impl<'a> Input<'a>

Source

pub fn new(prompt: &'a str) -> Self

Create a new Input builder with the given prompt text. If the prompt is empty, the prompt will not be displayed.

Source

pub fn default(self, value: &'a str) -> Self

Set a default value to return when the user enters nothing.

Source

pub fn trim(self, trim: bool) -> Self

Control whether leading/trailing whitespace is trimmed. Defaults to true.

Source

pub fn show_prompt(self, show: bool) -> Self

Control whether the prompt is displayed. Defaults to true when the prompt is non-empty.

Source

pub fn read(self) -> Result<String, InputError>

Read input from standard stdin/stdout.

Source

pub fn read_with_io<R: InputReader, W: OutputWriter>( self, reader: &mut R, writer: &mut W, ) -> Result<String, InputError>

Read input using custom reader/writer implementations. Useful for testing without actual I/O.

Auto Trait Implementations§

§

impl<'a> Freeze for Input<'a>

§

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> UnsafeUnpin for Input<'a>

§

impl<'a> UnwindSafe for Input<'a>

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.