As a rust newbie I have a problem finding an element in a vector of Option using the "find" function:
#[derive(Debug)]
struct MyStruct {
name: Option<String>,
data: Option<String>
}
fn main() {
let my_vec=vec![
MyStruct{
name:Some(String::from("name1")),
data:Some(String::from("data1"))
},
MyStruct{
name:Some(String::from("name2")),
data:Some(String::from("data2"))
}
];
let search_string = String::from("name2");
let found_record=my_vec.iter().find(|s| s.name == Some(search_string));
println!("{:?}", found_record);
}
This code does not compile because of the comparison s.name == Some(search_string) because of a missing Copy trait. What would be the correct way for the "find" expression?