fn matches<'a>(&self, rule: &Rule, msg: &'a str) -> Vec<&'a str> {
        //println!("Matching rule {:?} on {}", rule, msg);
        match rule {
            Rule::Literal(c) => {
                match msg.strip_prefix(*c) {
                    Some(msg_tail) => { vec![msg_tail] },
                    _ => { vec![] },
                }
            }
            Rule::And(list) => {
                match list.split_first() {
                    Some((i, tail)) => {
                        self.matches(&self.rules[i], msg)
                            .into_iter()
                            .flat_map(|msg_tail| self.matches(&Rule::And(tail.to_vec()), msg_tail))
                            .collect()
                    },
                    None => { vec![msg] },
                }
            }
            Rule::Or(list) => {
                list.iter().flat_map(|r| self.matches(r, msg)).collect()
            }
        }
    }
// Matches a rule in all possible ways on the initial part of a message,
// returning the possible leftover messages after positive matches.
Matches a rule in all possible ways on the initial part of a message,
returning the possible leftover messages after positive matches.
Matches a rule in all possible ways on the initial part of a message returning the possible leftover messages after positive matches .
fn matches<'a>(&self, rule: &Rule, msg: &'a str) -> Vec<&'a str> {
        //println!("Matching rule {:?} on {}", rule, msg);
        match rule {
            Rule::Literal(c) => {
                match msg.strip_prefix(*c) {
                    Some(msg_tail) => { vec![msg_tail] },
                    _ => { vec![] },
                }
            }
            Rule::And(list) => {
                match list.split_first() {
                    Some((i, tail)) => {
                        self.matches(&self.rules[i], msg)
                            .into_iter()
                            .flat_map(|msg_tail| self.matches(&Rule::And(tail.to_vec()), msg_tail))
                            .collect()
                    },
                    None => { vec![msg] },
                }
            }
            Rule::Or(list) => {
                list.iter().flat_map(|r| self.matches(r, msg)).collect()
            }
        }
    }
fn matches < ' a > ( & self , rule : & Rule , msg : & ' a str ) -> Vec < & ' a str > { //println!("Matching rule {:?} on {}", rule, msg); match rule { Rule :: Literal ( c ) => { match msg . strip_prefix ( * c ) { Some ( msg_tail ) => { vec ! [ msg_tail ] } , _ => { vec ! [ ] } , } } Rule :: And ( list ) => { match list . split_first ( ) { Some ( ( i , tail ) ) => { self . matches ( & self . rules [ i ] , msg ) . into_iter ( ) . flat_map ( | msg_tail | self . matches ( & Rule :: And ( tail . to_vec ( ) ) , msg_tail ) ) . collect ( ) } , None => { vec ! [ msg ] } , } } Rule :: Or ( list ) => { list . iter ( ) . flat_map ( | r | self . matches ( r , msg ) ) . collect ( ) } } }
Matches a rule in all possible ways on the initial part of a message,
returning the possible leftover messages after positive matches.
Matches a rule in all possible ways on the initial part of a message returning the possible leftover messages after positive matches .
&self
rule
&Rule
msg
&'a str