pub struct CellOptionRef<T: ?Sized> { /* private fields */ }
Expand description
Implementations§
Source§impl<T: ?Sized> CellOptionRef<T>
impl<T: ?Sized> CellOptionRef<T>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new CellOptionRef
containing None.
§Examples
use stack_cell_ref::CellOptionRef;
let c = CellOptionRef::<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::CellOptionRef;
let c = CellOptionRef::<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::CellOptionRef;
let cell = CellOptionRef::new();
let foo = 1;
cell.with(Some(&foo), || {
cell.read(|r| {
assert_eq!(*r.unwrap(), 1);
// ...
});
});
Sourcepub fn with<F: FnOnce() -> R, R>(&self, r: Option<&T>, f: F) -> R
pub fn with<F: FnOnce() -> R, R>(&self, r: Option<&T>, f: F) -> R
Set the cell pointer then run fn.
§Examples
use std::ptr::NonNull;
use stack_cell_ref::CellOptionRef;
let cell = CellOptionRef::new();
let foo = 1;
cell.with(Some(&foo), || {
assert_eq!(cell.get_ptr(), Some(NonNull::from(&foo)));
// ...
});
assert_eq!(cell.get_ptr(), None);
Trait Implementations§
Source§impl<T: ?Sized> Default for CellOptionRef<T>
impl<T: ?Sized> Default for CellOptionRef<T>
impl<T: Eq + ?Sized> Eq for CellOptionRef<T>
Auto Trait Implementations§
impl<T> !Freeze for CellOptionRef<T>
impl<T> !RefUnwindSafe for CellOptionRef<T>
impl<T> !Send for CellOptionRef<T>
impl<T> !Sync for CellOptionRef<T>
impl<T> Unpin for CellOptionRef<T>where
T: ?Sized,
impl<T> UnwindSafe for CellOptionRef<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