Hi there!
I have a type like this:
pub struct AtomWithHierarchyMut<'a> {
/// The Chain containing this Atom
pub chain: &'a Chain,
/// The Residue containing this Atom
pub residue: &'a Residue,
/// The Conformer containing this Atom
pub conformer: &'a Conformer,
/// This Atom
pub atom: RefCell<&'a Atom>,
}
and I want to mutate the atom
field in place. The Atom
struct in turn looks like this:
pub struct Atom {
...
/// The occupancy of the Atom
occupancy: f64,
...
}
And what I tried then is:
let atom_hi_mut = AtomWithHierarchyMut::new(chain, residue, conformer, RefCell::new(atom));
let mut atom_mut = atom_hi_mut.atom.borrow_mut();
// This method mutates the `occupancy` field.
atom_mut.set_occupancy(1.00)?;
But I get this error message:
cannot borrow data in a dereference of
RefMut<', &Atom>as mutable trait
DerefMutis required to modify through a dereference, but it is not implemented for
RefMut<', &Atom>``
I'm still trying to wrap my head around how RefCell
works and how I can use it to mutate stuff and it was my impression that I can use it for a case like this but I don't quite understand the error message. Do I need to implement DerefMut
for Atom
or does this hint at something else?