Struct Field

Source
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>

Source

pub fn valid(name: &'a str, val: &'a str) -> Field<'a>

Source

pub fn invalid(name: &'a str, val: &'a str) -> Field<'a>

Source

pub fn name(&self) -> &str

Source

pub fn value(&self) -> &str

Source

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§

Source§

impl Into<String> for Field<'_>

Source§

fn into(self) -> String

Converts this type into the (usually inferred) input type.

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> 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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
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.