Trait conciliator::input::Input
source · pub trait Input {
type T;
// Required methods
fn prompt(&self, buffer: &mut Buffer);
fn validate(&self, user_input: &str) -> Option<Self::T>;
// Provided method
fn print<C: Conciliator + ?Sized>(&mut self, con: &C) { ... }
}
Expand description
Requesting user input
Used by Claw::input
, where:
print
is called once at the start of the input procedure to establish the context of the input being requested,prompt
is called to prompt the user for input,- then, a line is read from the standard input and
trim
med before being passed to validate
, which (parses and) validates the input. If it returns
Required Associated Types§
Required Methods§
sourcefn prompt(&self, buffer: &mut Buffer)
fn prompt(&self, buffer: &mut Buffer)
Make the request
Provide a concise question or request, ideally indicating the expected format. In general, do not add a trailing newline.
This will be called at least once, and then again for every time validate
returns None
.
For example: Are you sure you want to continue? [y/N]:
Provided Methods§
sourcefn print<C: Conciliator + ?Sized>(&mut self, con: &C)
fn print<C: Conciliator + ?Sized>(&mut self, con: &C)
Establish the context of the request (optional, the provided method does nothing)
For example: to request a selection to be made from a List
of items, this function is implemented and Print
s the List
.
Then prompt
only specifies the range of valid indices.
This differs from the signature of Print
in that it takes &mut self
instead self
by value, because the Input
implementor will still be needed to prompt
and validate
.
Because of this, implementors of this that are wrappers around Print
implementors may chose to use the if let Some(p) = self.p.take() { p.print(con) }
pattern.