pub struct KeyCell<T: Meta>(/* private fields */);Expand description
A RefCell-like wrapper that can only be accessed via
Key.
Implementations§
Source§impl<T: Meta> KeyCell<T>
impl<T: Meta> KeyCell<T>
Sourcepub fn borrow<'a>(&'a self, _key: &'a Key) -> KeyCellRef<'a, T>
pub fn borrow<'a>(&'a self, _key: &'a Key) -> KeyCellRef<'a, T>
Immutably borrows the wrapped value.
§Examples
use mutcy::{Key, KeyCell};
let key = Key::acquire();
let kc = KeyCell::new(123, ());
let borrowed1 = kc.borrow(&key);
let borrowed2 = kc.borrow(&key);Sourcepub fn borrow_mut<'a>(&'a self, key: &'a mut Key) -> KeyCellMut<'a, T>
pub fn borrow_mut<'a>(&'a self, key: &'a mut Key) -> KeyCellMut<'a, T>
Mutably borrows the wrapped value.
Requires a &mut Key that ensures that no other borrows exist
simultaneously.
§Examples
use mutcy::{Key, KeyCell};
let mut key = Key::acquire();
let kc = KeyCell::new(123, ());
let borrowed1 = kc.borrow_mut(&mut key);
let borrowed2 = kc.borrow(&key);
// This does not compile.
// let _ = *borrowed1;Auto Trait Implementations§
impl<T> !Freeze for KeyCell<T>
impl<T> !RefUnwindSafe for KeyCell<T>
impl<T> Send for KeyCell<T>
impl<T> !Sync for KeyCell<T>
impl<T> Unpin for KeyCell<T>
impl<T> UnwindSafe for KeyCell<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more