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