Consider this structure with 2 fields on the heap that are needed to be updated in unison:
struct Both {
one: One,
two: Two,
}
impl Both {
fn update(&mut self, value: &Value) {
let mut one_attr = self.one.attr_borrow_mut(value);
let mut two_attr = self.two.attr_borrow_mut(value);
// ... mangled update of both one_attr and two_attr.
}
}
In this code the compiler will complain that self
is borrowed mutably more than once.
But is it possible to destructure Both
into a &mut
to both one
and two
? Assuming both One
and Two
are heap allocated, or otherwise have a fixed length, shouldn't that be safe?
Edit: playground example that sadly fails to show the proper error, since it is is missing a crate.