/// Starting at this node, recursively check (depth-first) any child nodes and
/// aggregate the results
Starting at this node, recursively check (depth-first) any child nodes and
aggregate the results
Starting at this node recursively check ( depth - first ) any child nodes and aggregate the results
pub fn check_value(&self, info: &Value) -> ConditionResult {
        match *self {
            Condition::And { ref and } => {
                let mut status = Status::Met;
                let children = and
                    .iter()
                    .map(|c| c.check_value(info))
                    .inspect(|r| status = status & r.status)
                    .collect::<Vec<_>>();
                ConditionResult {
                    name: "And".into(),
                    status,
                    children,
                }
            }
            Condition::Or { ref or } => {
                let mut status = Status::NotMet;
                let children = or
                    .iter()
                    .map(|c| c.check_value(info))
                    .inspect(|r| status = status | r.status)
                    .collect::<Vec<_>>();
                ConditionResult {
                    name: "Or".into(),
                    status,
                    children,
                }
            }
            Condition::AtLeast {
                should_minimum_meet,
                ref conditions,
            } => {
                let mut met_count = 0;
                let children = conditions
                    .iter()
                    .map(|c| c.check_value(info))
                    .inspect(|r| {
                        if r.status == Status::Met {
                            met_count += 1;
                        }
                    })
                    .collect::<Vec<_>>();
                let status = if met_count >= should_minimum_meet {
                    Status::Met
                } else {
                    Status::NotMet
                };
                ConditionResult {
                    name: format!(
                        "At least meet {} of {}",
                        should_minimum_meet,
                        conditions.len()
                    ),
                    status,
                    children,
                }
            }
            Condition::Condition {
                ref field,
                ref constraint,
            } => {
                let pointer = if field.starts_with("/") {
                    field.to_owned()
                } else {
                    format!("/{}", field)
                };
                let status = if let Some(s) = info.pointer(&pointer) {
                    constraint.check_value(s)
                } else {
                    Status::Unknown
                };
                ConditionResult {
                    name: field.to_owned(),
                    status,
                    children: Vec::new(),
                }
            }
        }
    }
pub fn check_value ( & self , info : & Value ) -> ConditionResult { match * self { Condition :: And { ref and } => { let mut status = Status :: Met ; let children = and . iter ( ) . map ( | c | c . check_value ( info ) ) . inspect ( | r | status = status & r . status ) . collect :: < Vec < _ > > ( ) ; ConditionResult { name : " " . into ( ) , status , children , } } Condition :: Or { ref or } => { let mut status = Status :: NotMet ; let children = or . iter ( ) . map ( | c | c . check_value ( info ) ) . inspect ( | r | status = status | r . status ) . collect :: < Vec < _ > > ( ) ; ConditionResult { name : " " . into ( ) , status , children , } } Condition :: AtLeast { should_minimum_meet , ref conditions , } => { let mut met_count = 0 ; let children = conditions . iter ( ) . map ( | c | c . check_value ( info ) ) . inspect ( | r | { if r . status == Status :: Met { met_count += 1 ; } } ) . collect :: < Vec < _ > > ( ) ; let status = if met_count >= should_minimum_meet { Status :: Met } else { Status :: NotMet } ; ConditionResult { name : format ! ( " " should_minimum_meet conditions len ( ) ) , status , children , } } Condition :: Condition { ref field , ref constraint , } => { let pointer = if field . starts_with ( " " ) { field . to_owned ( ) } else { format ! ( " " field ) } ; let status = if let Some ( s ) = info . pointer ( & pointer ) { constraint . check_value ( s ) } else { Status :: Unknown } ; ConditionResult { name : field . to_owned ( ) , status , children : Vec :: new ( ) , } } } }
Starting at this node, recursively check (depth-first) any child nodes and
aggregate the results
Starting at this node recursively check ( depth - first ) any child nodes and aggregate the results
&self
info
&Value