struct RefWrap<'a> {
wrap: &'a mut Option<String>,
}
impl<'a> RefWrap<'a> {
fn unwrap(&mut self) -> &'a mut String {
match *self.wrap {
Some(ref mut s) => s,
None => panic!(),
}
}
}
As far as I understand, this code is correct (the returned reference really has the lifetime 'a
. But Rust produces the following error:
error[E0495]: cannot infer an appropriate lifetime for pattern due to conflicting requirements
--> <anon>:8:18
|
8 | Some(ref mut s) => s,
| ^^^^^^^^^
Using immutable references, it works without an error.
There has been one similar question, but I'm pretty sure it's not helpful in this case.
See Question&Answers more detail:os