pub struct CellRef<T: ?Sized>(/* private fields */);Expand description
Implementations§
Source§impl<T: ?Sized> CellRef<T>
impl<T: ?Sized> CellRef<T>
Sourcepub fn get_ptr(&self) -> NonNull<T>
pub fn get_ptr(&self) -> NonNull<T>
Returns the contained pointer.
§Examples
use stack_cell_ref::CellRef;
let c = CellRef::<i32>::new_with(&0);
let ptr_to_zero = c.get_ptr();Sourcepub fn read<F: FnOnce(&T) -> R, R>(&self, f: F) -> R
pub fn read<F: FnOnce(&T) -> R, R>(&self, f: F) -> R
Read the cell ref.
§Examples
use stack_cell_ref::CellRef;
let cell = CellRef::new_with(&0);
let foo = 1;
cell.with(&foo, || {
cell.read(|r| {
assert_eq!(*r, 1);
// ...
});
});Sourcepub fn with<F: FnOnce() -> R, R>(&self, r: &T, f: F) -> R
pub fn with<F: FnOnce() -> R, R>(&self, r: &T, f: F) -> R
Set the cell pointer then run fn.
§Examples
use std::ptr::NonNull;
use stack_cell_ref::CellRef;
let cell = CellRef::new_with(&0);
let foo = 1;
cell.with(&foo, || {
assert_eq!(cell.get_ptr(), NonNull::from(&foo));
// ...
});
assert_eq!(unsafe { *cell.get_ptr().as_ref() }, 0);Trait Implementations§
impl<T: Eq + ?Sized> Eq for CellRef<T>
Auto Trait Implementations§
impl<T> !Freeze for CellRef<T>
impl<T> !RefUnwindSafe for CellRef<T>
impl<T> !Send for CellRef<T>
impl<T> !Sync for CellRef<T>
impl<T> Unpin for CellRef<T>where
T: ?Sized,
impl<T> UnwindSafe for CellRef<T>where
T: RefUnwindSafe + ?Sized,
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