pub struct JailValueMut<'a, T> { /* private fields */ }Expand description
A guarded wrapper around a mutable reference to the value contained in a JailCell
JailValueMut
As long as the JailValueMut remains in scope, the value in JailCell will remain marked as mutably referenced and unable to be referenced a second time. You can manually drop the JailValueMut out of scope by passing it as the first parameter to the function [JailValueMut::unguard(jail_val_mut)]
You can obtain a JailValueMut by calling guard_mut() on a JailCell
§Example
let jail: JailCell<u32> = JailCell::new(42);
let mut grd_mut = jail.guard_mut()?;
assert_eq!(*grd_mut, 42);
*grd_mut = 69;
JailValueMut::unguard(grd_mut);
jail.visit_ref(|val| {
assert_eq!(*val, 69);
Ok(())
});Implementations§
Source§impl<'a, T> JailValueMut<'a, T>
impl<'a, T> JailValueMut<'a, T>
Sourcepub fn unguard(_guarded_jail_value: JailValueMut<'a, T>)
pub fn unguard(_guarded_jail_value: JailValueMut<'a, T>)
Manually end a JailValueMut value’s temporary guarded absence from the JailCell
This method simply takes ownership of the JailValueMut and immediately lets it go out of scope,
causing it’s drop() method to be called and clearing its mutable reference in the JailCell
§Example
let jail: JailCell<u32> = JailCell::new(42);
let grd_mut = jail.guard_mut()?;
// val CANNOT be referenced again because the mutable reference is still in scope
assert!(jail.visit_ref(|val| Ok(())).is_err());
JailValueMut::unguard(grd_mut);
// val CAN be referenced again because the mutable reference was dropped
assert!(jail.visit_ref(|val| Ok(())).is_ok());