[][src]Struct cherries::validate::ValidateChain

pub struct ValidateChain<T: Clone + Debug> {
    pub cherry: Cherry<T>,
    pub errors: RefCell<Vec<String>>,
}

Fields

cherry: Cherry<T>errors: RefCell<Vec<String>>

Methods

impl<T: Clone + Debug> ValidateChain<T>[src]

Immediate proxy for validation

Provides method into_result to aggregate validation error.

pub fn into_result(self) -> Result<T>[src]

Aggregates validation error.

Coverts ValidateProxy<T> to cherries::Result<T>.

Examples

extern crate cherries;
use cherries::{node::Leaf, validate::{Validate, Error}};
extern crate uom;
use uom::si::{f32::*, length::meter, area::square_meter};

fn main() {
   let x = Leaf::new()
       .name("x")
       .value(Length::new::<meter>(2.0))
       .build();
   let y = Leaf::new()
       .name("y")
       .value(Length::new::<meter>(1.0))
       .build();
   let res = x * y;
   let validated = res
       .validate("must be less than 1.0!!", |quantity| {
           quantity < &Area::new::<square_meter>(1.0)
       })
       .validate("must be less than 0.0!!", |quantity| {
           quantity < &Area::new::<square_meter>(0.0)
       })
       .into_result();
   assert_eq!(
       Err(Error {
           label: "(mul)".to_string(),
           msg: vec![
                "must be less than 1.0!!".to_string(),
                "must be less than 0.0!!".to_string()
           ],
           tree: "json tree".to_string(),
       }),
       validated
   );
}

Trait Implementations

impl<T: Clone + Debug> Validate<T> for ValidateChain<T>[src]

For validation chaining.

self.validate(predicate) returns ValidateProxy<T>.

Examples

extern crate cherries;
use cherries::{node::Leaf, validate::{Validate, Error}};
extern crate uom;
use uom::si::{f32::*, length::meter, area::square_meter};

fn main() {
   let x = Leaf::new()
       .name("x")
       .value(Length::new::<meter>(2.0))
       .build();
   let y = Leaf::new()
       .name("y")
       .value(Length::new::<meter>(1.0))
       .build();
   let res = x * y;
   let validated = res
       .validate("must be less than 1.0!!", |quantity| {
           quantity < &Area::new::<square_meter>(1.0)
       })
       .validate("must be less than 0.0!!", |quantity| {
           quantity < &Area::new::<square_meter>(0.0)
       })
       .into_result();
   assert_eq!(
       Err(Error {
           label: "(mul)".to_string(),
           msg: vec![
                "must be less than 1.0!!".to_string(),
                "must be less than 0.0!!".to_string()
           ],
           tree: "json tree".to_string(),
       }),
       validated
   );
}

Auto Trait Implementations

impl<T> Send for ValidateChain<T> where
    T: Send

impl<T> Unpin for ValidateChain<T> where
    T: Unpin

impl<T> !Sync for ValidateChain<T>

impl<T> UnwindSafe for ValidateChain<T> where
    T: UnwindSafe

impl<T> !RefUnwindSafe for ValidateChain<T>

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self