I wonder, what is the difference between the following three examples regarding the x
variable.
use std::collections::HashMap;
#[derive(PartialEq, Eq, Hash)]
enum SomeEnum {
One,
Two,
Three,
}
struct SomeStruct {
}
fn func(hm: &HashMap<SomeEnum, HashMap<SomeEnum, SomeStruct>>) -> Option<SomeStruct> {
if let Some(x) = hm.get(&SomeEnum::One)?.get(&SomeEnum::Two) {
//first
}
if let Some(x) = hm.get(&SomeEnum::One).unwrap().get(&SomeEnum::Two).as_ref() {
//second
}
if let Some(&x) = hm.get(&SomeEnum::One).unwrap().get(&SomeEnum::Two).as_ref() {
//third
}
None
}
I do not get the difference between these three different ways to get the &SomeStruct
.
Is it there?