// Find, or at least try to find regex in Tip's component
Find, or at least try to find regex in Tip's component
Find or at least try to find regex in Tip ' s component
fn find<'a, 'b, 'c>(
    regex: &'a regex::Regex,
    tip: &'b crate::tip::Tip,
    component: &'c Component) -> Option<&'b crate::tip::Tip> {
    match component {
        // Search the Subject component
        Component::Subject => {
            match regex.find(&tip.metadata.subject) {
                Some(_) => Some(tip),
                None    => None,
            }
        },
        // Search the Tip's data component
        Component::Data => {
            match regex.find(&tip.get_data()) {
                Some(_) => Some(tip),
                None    => None,
            }
        },
        // Search the Tip's tags component
        Component::Tag => {
            for tag in tip.metadata.tags.iter() {
                if let Some(_match) = regex.find(&format!("{:?}", tag)) {
                    return Some(tip);
                }
            }
            None
        },
        // Search all components (or as long we need until a hit)
        Component::All => {
            if let Some(m) = find(regex, tip, &Component::Subject) {
                Some(m)
            }
            else if let Some(m) = find(regex, tip, &Component::Data) {
                Some(m)
            }
            else if let Some(m) = find(regex, tip, &Component::Tag) {
                Some(m)
            }
            else {
                None
            }
        },
    }
}
fn find < ' a , ' b , ' c > ( regex : & ' a regex :: Regex , tip : & ' b crate :: tip :: Tip , component : & ' c Component ) -> Option < & ' b crate :: tip :: Tip > { match component { // Search the Subject component Component :: Subject => { match regex . find ( & tip . metadata . subject ) { Some ( _ ) => Some ( tip ) , None => None , } } , // Search the Tip's data component Component :: Data => { match regex . find ( & tip . get_data ( ) ) { Some ( _ ) => Some ( tip ) , None => None , } } , // Search the Tip's tags component Component :: Tag => { for tag in tip . metadata . tags . iter ( ) { if let Some ( _match ) = regex . find ( & format ! ( " " tag ) ) { return Some ( tip ) ; } } None } , // Search all components (or as long we need until a hit) Component :: All => { if let Some ( m ) = find ( regex , tip , & Component :: Subject ) { Some ( m ) } else if let Some ( m ) = find ( regex , tip , & Component :: Data ) { Some ( m ) } else if let Some ( m ) = find ( regex , tip , & Component :: Tag ) { Some ( m ) } else { None } } , } }
Find, or at least try to find regex in Tip's component
Find or at least try to find regex in Tip ' s component
regex
&'a regex::Regex
tip
&'b crate::tip::Tip
component
&'c Component