Skip to content

Instantly share code, notes, and snippets.

@totem3
Created January 24, 2018 21:30
Show Gist options
  • Save totem3/057b8abfad937ba40e53c115428a673d to your computer and use it in GitHub Desktop.
Save totem3/057b8abfad937ba40e53c115428a673d to your computer and use it in GitHub Desktop.
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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment