Skip to main content

Form

Struct Form 

Source
pub struct Form { /* private fields */ }
Expand description

The validation report of a set of fields, in declaration order. Built by chaining Form::field, then consulted. The values are recorded so that cross-field validation is possible: one field compared with another.

Implementations§

Source§

impl Form

Source

pub fn new() -> Self

An empty form (everything is valid while no field is declared).

Source

pub fn field(self, key: &'static str, value: &str, rule: Rule) -> Self

Validates value with rule and records the result under key.

Source

pub fn field_with( self, key: &'static str, value: &str, check: impl Fn(&str, &Form) -> Option<String>, ) -> Self

Validates a field with a cross-field function receiving its value and the partial form (the fields already declared): check(value, form) can consult form.value(other) — a confirmed password, consistent dates, and so on. So declare the referenced field first.

Source

pub fn matches( self, key: &'static str, value: &str, other: &'static str, message: impl Into<String>, ) -> Self

A cross-field convenience: value must equal field other’s value (already declared) — the “confirm the password” case. Otherwise message.

Source

pub fn value(&self, key: &str) -> Option<&str>

Field key’s recorded value, for cross-field validation.

Source

pub fn is_valid(&self) -> bool

true if no field is in error.

Source

pub fn error(&self, key: &str) -> Option<&str>

Field key’s error message, if it has one.

Source

pub fn errors(&self) -> Vec<(&'static str, &str)>

Every error message as (key, message), in declaration order — for a summary at the head of the form (see ErrorSummary).

Source

pub fn first_invalid(&self) -> Option<&'static str>

The key of the first field in error (declaration order) — typically the one to focus or bring out on submission.

Trait Implementations§

Source§

impl Default for Form

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Form

§

impl RefUnwindSafe for Form

§

impl Send for Form

§

impl Sync for Form

§

impl Unpin for Form

§

impl UnsafeUnpin for Form

§

impl UnwindSafe for Form

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<Msg> IntoMsg<Msg> for Msg

Source§

fn defer(work: impl Fn() -> Msg + 'static) -> Msg

The message that stands for work’s result.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.