Enum Constraint

Source
pub enum Constraint<'a> {
    MinLength(usize),
    MaxLength(usize),
    MinNumber(f64),
    MaxNumber(f64),
    MinDate(&'a str),
    MaxDate(&'a str),
    MinDateTime(&'a str),
    MaxDateTime(&'a str),
    MinTime(&'a str),
    MaxTime(&'a str),
    Pattern(&'a str),
    Func(Box<dyn Fn(&Value) -> Result<(), ValidationError>>),
}
Expand description

Constraints on Field values, perform validation.

All of the constraints cause server-side validation to be performed, all except Constraint::Func should - assuming they’re serialized properly - result in client-side validation. HTML validity is checked when adding the constraints to the fields using HtmlForm’s builder methods.

Variants§

§

MinLength(usize)

Constraint on most inputs.

§

MaxLength(usize)

Constraint on most inputs.

§

MinNumber(f64)

Constraint on number and range inputs.

§

MaxNumber(f64)

Constraint on number and range inputs.

§

MinDate(&'a str)

Constraint on date input.

§

MaxDate(&'a str)

Constraint on date input.

§

MinDateTime(&'a str)

Constraint on datetime-local input.

§

MaxDateTime(&'a str)

Constraint on datetime-local input.

§

MinTime(&'a str)

Constraint on time input.

§

MaxTime(&'a str)

Constraint on time input.

§

Pattern(&'a str)

Constraint on most Element::Input fields, causes regex pattern validation (both on the server and the client, note that the pattern therefore must execute correctly on both sides).

§

Func(Box<dyn Fn(&Value) -> Result<(), ValidationError>>)

Constraint on any field, is executed server-side only and not serialized.

Implementations§

Source§

impl<'a> Constraint<'a>

Source

pub fn validate(&self, formvalue: &Value) -> Result<(), ValidationError>

Validate a single, non-empty Value.

Source

pub fn attrpair(&self) -> Option<(String, String)>

Returns the name and value of the HTML attribute of the Constraint.

Returns None for Constraint::Func, as that is only functional on the server side.

Source

pub fn allowed_on(&self, element: &Element) -> bool

Return true if this Constraint is allowed on element, false otherwise.

Trait Implementations§

Source§

impl<'a> Debug for Constraint<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Constraint<'a>

§

impl<'a> !RefUnwindSafe for Constraint<'a>

§

impl<'a> !Send for Constraint<'a>

§

impl<'a> !Sync for Constraint<'a>

§

impl<'a> Unpin for Constraint<'a>

§

impl<'a> !UnwindSafe for Constraint<'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, 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.