pub struct RuleBuilder<'a, R, V, E: PartialEq + Eq + Send + Sync> { /* private fields */ }Expand description
Fluent wrapper around a KpType (key path) and a set of validation functions.
R is the root type you pass to RuleBuilder::with_root; V is the value type at
the end of the path (often String). E is your error payload (e.g. String).
Rule functions must be fn pointers (not closures that capture state) so they can be stored
in a Vec and shared across Rayon threads.
Implementations§
Source§impl<'a, R, V, E> RuleBuilder<'a, R, V, E>
impl<'a, R, V, E> RuleBuilder<'a, R, V, E>
Sourcepub fn new(kp: KpType<'a, R, V>) -> Self
pub fn new(kp: KpType<'a, R, V>) -> Self
Starts a builder for the given statically dispatched key path (#[derive(Kp)] fields).
Sourcepub fn with_root(self, root: &'a R) -> Self
pub fn with_root(self, root: &'a R) -> Self
Supply the struct instance root that the key path reads from.
Sourcepub fn rule(self, f: fn(Option<&'a V>) -> RuleBuilderError<E>) -> Self
pub fn rule(self, f: fn(Option<&'a V>) -> RuleBuilderError<E>) -> Self
Append a rule executed in parallel with other non-mandatory rules when you call
apply.
Sourcepub fn mandatory_rule(self, f: fn(Option<&'a V>) -> RuleBuilderError<E>) -> Self
pub fn mandatory_rule(self, f: fn(Option<&'a V>) -> RuleBuilderError<E>) -> Self
Sourcepub fn madatory_rule(self, f: fn(Option<&'a V>) -> RuleBuilderError<E>) -> Self
👎Deprecated: use mandatory_rule
pub fn madatory_rule(self, f: fn(Option<&'a V>) -> RuleBuilderError<E>) -> Self
use mandatory_rule
Deprecated typo; use Self::mandatory_rule.
Sourcepub fn apply(&self) -> Vec<RuleBuilderError<E>>
pub fn apply(&self) -> Vec<RuleBuilderError<E>>
Resolves Option<&V> via the key path, runs mandatory rules, then runs remaining rules on
a Rayon thread pool.
Auto Trait Implementations§
impl<'a, R, V, E> Freeze for RuleBuilder<'a, R, V, E>
impl<'a, R, V, E> RefUnwindSafe for RuleBuilder<'a, R, V, E>where
R: RefUnwindSafe,
V: RefUnwindSafe,
impl<'a, R, V, E> Send for RuleBuilder<'a, R, V, E>where
R: Sync,
impl<'a, R, V, E> Sync for RuleBuilder<'a, R, V, E>where
R: Sync,
impl<'a, R, V, E> Unpin for RuleBuilder<'a, R, V, E>
impl<'a, R, V, E> UnsafeUnpin for RuleBuilder<'a, R, V, E>
impl<'a, R, V, E> !UnwindSafe for RuleBuilder<'a, R, V, E>
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
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