Closed
Description
Asked on reddit
I have a program where I want to select from two fields (int in this example, io::Writer in practice). It is not possible to return a in a way the program compiles.
Reborrowing was suggested (&mut *self.a
) but you can't do that with io::Writer
references.
pub struct Foo<'a> {
priv a: &'a mut int,
priv b: int,
priv take_a: bool
}
impl<'a> Foo<'a> {
fn take(&'a mut self) -> &'a mut int {
if self.take_a {
self.a
} else {
&mut self.b
}
}
}