One more awkward beginner-question please!
struct MyStruct {
s: Option<String>
}
impl MyStruct {
fn setIfUnset(&mut self) {
match &mut self.s {
& mut Some(ref s) => { /* omitted here */}
& mut None => {
self.s = Some(String::from(" I Wandered Lonely as a Cloud "))
}
}
}
}
Compiler claims an error:
& mut None => self.s = Some(String::from(" I Wandered Lonely as a Cloud "))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed self.s
occurs here
But how am I supposed to set "self.s" in the case, it is none?
"self.s is borrowed" - OK. But how can I access this borrow?
Benedikt