So this is my situation:
let map: HashMap<String, String> = HashMap::new();
let key = String::from("key");
let v = map.get(&key).unwrap_or(&String::from("key not found"));
println!("{}", v);
And this is my error:
temporary value is freed at the end of this statement creates a temporary which is freed while still in use
Being quite new to Rust I'm not sure if I'm using String
properly or if str
or &str
would be more appropriate, but in any case I'm not exactly sure how I could use unwrap_or
in this case to return a reference to a String
. I know I could use pattern matching but I would prefer this pattern.