Skip to main content

DatetimeValidator

Struct DatetimeValidator 

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

Validator for ISO-8601 style datetime strings.

Implementations§

Source§

impl DatetimeValidator

Source

pub fn new() -> Self

Create a new validator.

Source§

impl DatetimeValidator

Source

pub fn optional(self) -> Self

Make the field optional (equivalent to required = false).

Source

pub fn nullable(self) -> Self

Allow the field to be explicitly null.

Source

pub fn required(self) -> Self

Mark the field as required.

Source

pub fn sensitive(self, sensitive: bool) -> Self

Mark the field as sensitive (e.g. passwords, tokens).

When enabled, every error this validator produces redacts the offending value: message interpolations render as *** and ValidationError::value is None, so errors can be logged safely. The flag is per-validator and is NOT inherited by nested validators.

Source

pub fn custom<F>(self, f: F) -> Self
where F: Fn(&Value) -> Option<String> + Send + Sync + 'static,

Add a custom validation function.

The function receives the value and should return Some(message) when invalid. Custom validators run after type and constraint checks.

Source

pub fn fail_fast(self, fail_fast: bool) -> Self

Stop at the first validation error.

When enabled, validation returns a result containing exactly one error. The flag is propagated to nested validators.

Trait Implementations§

Source§

impl Default for DatetimeValidator

Source§

fn default() -> Self

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

impl Validator for DatetimeValidator

Source§

fn set_fail_fast(&mut self, fail_fast: bool)

Set fail-fast mode for this validator and its children.
Source§

fn validate(&self, value: &Value, field: &str) -> ValidationResult

Validate value at the given field path.
Source§

fn is_required(&self) -> bool

Whether the field is required.
Source§

fn is_nullable(&self) -> bool

Whether the field may be explicitly null.

Auto Trait Implementations§

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 = !

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.