totem3
1/24/2018 - 9:30 PM

x.rs

fn is_foo(s: &str) -> bool {
    s == "foo"
}

fn is_bar<S: PartialEq<str> + AsRef<str>>(s: &&S) -> bool {
    s.as_ref() == "bar"
}

fn main() {
    let v: Vec<String> = vec!["foo".to_owned()];
    
    let x: Vec<&String> = v.iter().filter(|s| is_foo(s)).collect();
    println!("{:?}", x);
    
    let x: Vec<&String> = v.iter().filter(is_bar).collect();
    println!("{:?}", x);
}