-
-
Save totem3/057b8abfad937ba40e53c115428a673d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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