pub struct Accumulator {
pub prefix: Vec<Key>,
/* private fields */
}Expand description
Type used to build up a list of validation failures.
When validating fields of a struct while validating that struct,
push the field’s name (or index in a sequence)
onto the prefix member of the accumulator
before passing it in to the validator.
This allows nested fields to report where the failure happened.
use validatrix::Accumulator;
let mut accum = Accumulator::default();
accum.prefix.push("some_field".into());
// ... validate `some_field` using this accumulator
accum.prefix.pop();Fields§
§prefix: Vec<Key>This prefix is applied to any failures added to the accumulator.
Implementations§
Source§impl Accumulator
impl Accumulator
Sourcepub fn add_failure(&mut self, failure: Failure, keys: &[Key])
pub fn add_failure(&mut self, failure: Failure, keys: &[Key])
Add one extra failure to this accumulator, under the given keys.
Sourcepub fn accumulate_err(&mut self, res: Result<(), Error>, keys: &[Key]) -> bool
pub fn accumulate_err(&mut self, res: Result<(), Error>, keys: &[Key]) -> bool
Ingest a whole error response into this accumulator, under the given keys.
If a failure was added, returns true.
Sourcepub fn validate_iter<'a, V: Validate + 'a, I: IntoIterator<Item = &'a V>>(
&mut self,
items: I,
) -> usize
pub fn validate_iter<'a, V: Validate + 'a, I: IntoIterator<Item = &'a V>>( &mut self, items: I, ) -> usize
If a failure was added, returns > 0
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Trait Implementations§
Source§impl Debug for Accumulator
impl Debug for Accumulator
Source§impl Default for Accumulator
impl Default for Accumulator
Source§fn default() -> Accumulator
fn default() -> Accumulator
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for Accumulator
impl RefUnwindSafe for Accumulator
impl Send for Accumulator
impl Sync for Accumulator
impl Unpin for Accumulator
impl UnwindSafe for Accumulator
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
Mutably borrows from an owned value. Read more