fn find_predicate_required_id(predicate: &Predicate) -> Option<(&Expr, Vec<Predicate>)> {
    match predicate {
        Predicate::Field(name, id_predicate) if name == "id" => {
            if let Predicate::Expr(id_expr) = &**id_predicate {
                return Some((id_expr, vec![]));
            }
        }

        Predicate::And(predicates) => {
            // Search the sub-predicates of this conjunction for one that
            // requires a specific id.
            if let Some((i, id, child_remainder)) =
                predicates.iter().enumerate().find_map(|(i, p)| {
                    find_predicate_required_id(p)
                        .map(|(id, child_remainder)| (i, id, child_remainder))
                }) {
                // predicates[i] requires a specific id. We've hoisted out the
                // id expression, so replace predicates[i] with child_remainder.
                return Some((id, splice(predicates, i, child_remainder)));
            }
        }

        // We could also look into conjunctions, to see if any sub-predicate
        // requires a specific id. The nice code for this uses find_map, which
        // isn't stable yet.
        _ => (),
    }

    None
}
/// If `predicate` only admits `Node`s whose id is equal to a specific
/// expression, then return that expression, together with a vector of
/// `Predicates` that must also match, representing the parts of `predicate`
/// other than the `id`. These are the subterms of an implicit conjunction. The
/// vector may be empty.
///
/// Note that if we do have to construct a remainder predicate, it must be
/// constructed afresh, since we can't modify the predicate we were handed.
/// Since we use `Box` and not `Rc` in our parse tree, this could end up copying
/// a lot if the remainder predicate is large.


Note that if we do have to construct a remainder predicate, it must be
constructed afresh, since we can't modify the predicate we were handed.
Since we use `Box` and not `Rc` in our parse tree, this could end up copying
a lot if the remainder predicate is large.
Note that if we do have to construct a remainder predicate it must be constructed afresh since we can ' t modify the predicate we were handed . Since we use ` Box ` and not ` Rc ` in our parse tree this could end up copying a lot if the remainder predicate is large .
fn find_predicate_required_id(predicate: &Predicate) -> Option<(&Expr, Vec<Predicate>)> {
    match predicate {
        Predicate::Field(name, id_predicate) if name == "id" => {
            if let Predicate::Expr(id_expr) = &**id_predicate {
                return Some((id_expr, vec![]));
            }
        }
        Predicate::And(predicates) => {
            // Search the sub-predicates of this conjunction for one that
            // requires a specific id.
            if let Some((i, id, child_remainder)) =
                predicates.iter().enumerate().find_map(|(i, p)| {
                    find_predicate_required_id(p)
                        .map(|(id, child_remainder)| (i, id, child_remainder))
                }) {
                // predicates[i] requires a specific id. We've hoisted out the
                // id expression, so replace predicates[i] with child_remainder.
                return Some((id, splice(predicates, i, child_remainder)));
            }
        }
        // We could also look into conjunctions, to see if any sub-predicate
        // requires a specific id. The nice code for this uses find_map, which
        // isn't stable yet.
        _ => (),
    }
    None
}
fn find_predicate_required_id ( predicate : & Predicate ) -> Option < ( & Expr , Vec < Predicate > ) > { match predicate { Predicate :: Field ( name , id_predicate ) if name == " " => { if let Predicate :: Expr ( id_expr ) = & * * id_predicate { return Some ( ( id_expr , vec ! [ ] ) ) ; } } Predicate :: And ( predicates ) => { // Search the sub-predicates of this conjunction for one that // requires a specific id. if let Some ( ( i , id , child_remainder ) ) = predicates . iter ( ) . enumerate ( ) . find_map ( | ( i , p ) | { find_predicate_required_id ( p ) . map ( | ( id , child_remainder ) | ( i , id , child_remainder ) ) } ) { // predicates[i] requires a specific id. We've hoisted out the // id expression, so replace predicates[i] with child_remainder. return Some ( ( id , splice ( predicates , i , child_remainder ) ) ) ; } } // We could also look into conjunctions, to see if any sub-predicate // requires a specific id. The nice code for this uses find_map, which // isn't stable yet. _ => ( ) , } None }
If `predicate` only admits `Node`s whose id is equal to a specific
expression, then return that expression, together with a vector of
`Predicates` that must also match, representing the parts of `predicate`
other than the `id`.
If ` predicate ` only admits ` Node ` s whose id is equal to a specific expression then return that expression together with a vector of ` Predicates ` that must also match representing the parts of ` predicate ` other than the ` id ` .
predicate
&Predicate
predicate
&Predicate