In the following snippet, I do not understand why the closure takes its parameter s
by reference (&s
), then dereferences it (*s
):
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...");
}
}
Am I missing something obvious?