pub struct Field<'a> { /* private fields */ }
Expand description
A reference to a specific field’s data in a form that also indicates whether or not it’s valid.
Implementations§
Source§impl<'a> Field<'a>
impl<'a> Field<'a>
pub fn valid(name: &'a str, val: &'a str) -> Field<'a>
pub fn invalid(name: &'a str, val: &'a str) -> Field<'a>
pub fn name(&self) -> &str
pub fn value(&self) -> &str
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Examples found in repository?
examples/minimal.rs (line 70)
62fn handle_input(state: &mut State) -> io::Result<()> {
63 if event::poll(Duration::from_millis(250))? {
64 if let Event::Key(key) = event::read()? {
65 match state.form.selected() {
66 FormSelection::NoSelection => match key.code {
67 KeyCode::Esc | KeyCode::Char('q') => state.should_quit = true,
68 KeyCode::Char('s') => {
69 let fields = state.form.submit();
70 if fields.iter().any(|f| !f.is_valid()) {
71 } else {
72 // Field impls Into<String>
73 state.submissions = Some(fields.into_iter().map(Into::into).collect());
74
75 state.form.deselect();
76 }
77 }
78 _ => {}
79 },
80 _ => {}
81 }
82
83 state.form.input(key.code);
84 }
85 }
86
87 Ok(())
88}
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Field<'a>
impl<'a> RefUnwindSafe for Field<'a>
impl<'a> Send for Field<'a>
impl<'a> Sync for Field<'a>
impl<'a> Unpin for Field<'a>
impl<'a> UnwindSafe for Field<'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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more