pub struct Validate { /* private fields */ }Expand description
Multi-field procedural validation builder for transaction scripts.
Accumulates field errors in deterministic key order and returns
SlabError::ValidationErrors (HTTP 422) from Validate::finish.
Implementations§
Source§impl Validate
impl Validate
Sourcepub fn required(&mut self, field: impl Into<String>, value: &str) -> &mut Self
pub fn required(&mut self, field: impl Into<String>, value: &str) -> &mut Self
Requires value to be non-empty after trimming whitespace.
Records "is required" under field when empty.
Sourcepub fn min_len(
&mut self,
field: impl Into<String>,
value: &str,
min: usize,
) -> &mut Self
pub fn min_len( &mut self, field: impl Into<String>, value: &str, min: usize, ) -> &mut Self
Requires the trimmed value to have at least min Unicode scalar characters.
Sourcepub fn max_len(
&mut self,
field: impl Into<String>,
value: &str,
max: usize,
) -> &mut Self
pub fn max_len( &mut self, field: impl Into<String>, value: &str, max: usize, ) -> &mut Self
Requires the trimmed value to have at most max Unicode scalar characters.
Sourcepub fn email(&mut self, field: impl Into<String>, value: &str) -> &mut Self
pub fn email(&mut self, field: impl Into<String>, value: &str) -> &mut Self
Requires the trimmed value to look like an email address.
Checks that the trimmed string is non-empty, contains no whitespace, and has a
non-empty local part before @ and a domain containing . after @.
Sourcepub fn url(&mut self, field: impl Into<String>, value: &str) -> &mut Self
pub fn url(&mut self, field: impl Into<String>, value: &str) -> &mut Self
Requires the trimmed value to start with http:// or https:// followed by a host.
Sourcepub fn one_of(
&mut self,
field: impl Into<String>,
value: &str,
allowed: &[&str],
) -> &mut Self
pub fn one_of( &mut self, field: impl Into<String>, value: &str, allowed: &[&str], ) -> &mut Self
Requires value to match one of the entries in allowed.
Sourcepub fn check(
&mut self,
field: impl Into<String>,
condition: bool,
message: impl Into<String>,
) -> &mut Self
pub fn check( &mut self, field: impl Into<String>, condition: bool, message: impl Into<String>, ) -> &mut Self
Records message under field when condition is false.
Sourcepub fn push(
&mut self,
field: impl Into<String>,
message: impl Into<String>,
) -> &mut Self
pub fn push( &mut self, field: impl Into<String>, message: impl Into<String>, ) -> &mut Self
Unconditionally appends message to the error list for field.
Sourcepub fn errors(&self) -> &BTreeMap<String, Vec<String>>
pub fn errors(&self) -> &BTreeMap<String, Vec<String>>
Returns the map of field names to accumulated validation messages.
Sourcepub fn finish(self) -> SlabResult<()>
pub fn finish(self) -> SlabResult<()>
Finalizes validation, returning Ok(()) when empty or SlabError::ValidationErrors.
Trait Implementations§
Auto Trait Implementations§
impl Forget for Validate
impl Freeze for Validate
impl Move for Validate
impl RefUnwindSafe for Validate
impl Send for Validate
impl Sync for Validate
impl Unpin for Validate
impl UnsafeUnpin for Validatewhere
*const LeafNode<String, Vec<String>> is !null: UnsafeUnpin,
PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin,
PhantomData<Box<(String, Vec<String>)>>: UnsafeUnpin,
impl UnwindSafe for Validate
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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> ⓘ
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> ⓘ
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