The following code doesn't compile because assigning a to b returns: expected struct std::string::String
, found &std::string::String
. I thought &s was &Option and not &Option<&T>. It seems that &s is behaving exactly like s.as_ref(). What's the reason behind this behavior?
fn main() {
let s = Some("string".to_string());
if let Some(a) = &s {
let b: String = a;
println!("{}", b);
}
}