Skip to content

Instantly share code, notes, and snippets.

@LeoBorai
Forked from patshaughnessy/find_string_example.rs
Created November 22, 2020 23:39
Show Gist options
  • Save LeoBorai/deb408eed4ed53c1c59f41a06c225623 to your computer and use it in GitHub Desktop.
Save LeoBorai/deb408eed4ed53c1c59f41a06c225623 to your computer and use it in GitHub Desktop.
Rust Vec<String> find example
fn main() {
let needle = "list".to_string();
let haystack = ["some".to_string(), "long".to_string(), "list".to_string(), "of".to_string(), "strings".to_string()].to_vec();
if let Some(str) = haystack.iter().find(|&s| *s == needle) {
println!("{}", needle);
} else {
println!("Nothing there...");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment