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>
impl<'a> Input<'a>
Sourcepub fn new(prompt: &'a str) -> Self
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.
Sourcepub fn default(self, value: &'a str) -> Self
pub fn default(self, value: &'a str) -> Self
Set a default value to return when the user enters nothing.
Sourcepub fn trim(self, trim: bool) -> Self
pub fn trim(self, trim: bool) -> Self
Control whether leading/trailing whitespace is trimmed.
Defaults to true.
Sourcepub fn show_prompt(self, show: bool) -> Self
pub fn show_prompt(self, show: bool) -> Self
Control whether the prompt is displayed.
Defaults to true when the prompt is non-empty.
Sourcepub fn read(self) -> Result<String, InputError>
pub fn read(self) -> Result<String, InputError>
Read input from standard stdin/stdout.
Sourcepub fn read_with_io<R: InputReader, W: OutputWriter>(
self,
reader: &mut R,
writer: &mut W,
) -> Result<String, InputError>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more