Struct stack_cell_ref::CellRef
source · pub struct CellRef<T: ?Sized>(/* private fields */);Expand description
Implementations§
source§impl<T: ?Sized> CellRef<T>
impl<T: ?Sized> CellRef<T>
sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new CellRef containing None.
§Examples
use stack_cell_ref::CellRef;
let c = CellRef::<i32>::new();sourcepub fn get_ptr(&self) -> Option<NonNull<T>>
pub fn get_ptr(&self) -> Option<NonNull<T>>
Returns the contained pointer.
§Examples
use stack_cell_ref::CellRef;
let c = CellRef::<i32>::new();
let none = c.get_ptr();sourcepub fn read<F: FnOnce(Option<&T>) -> R, R>(&self, f: F) -> R
pub fn read<F: FnOnce(Option<&T>) -> R, R>(&self, f: F) -> R
Read the cell ref.
§Examples
use stack_cell_ref::CellRef;
let cell = CellRef::new();
let foo = 1;
cell.with(&foo, || {
cell.read(|r| {
assert_eq!(*r.unwrap(), 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();
let foo = 1;
cell.with(&foo, || {
assert_eq!(cell.get_ptr(), Some(NonNull::from(&foo)));
// ...
});
assert_eq!(cell.get_ptr(), None);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