source ·
pub struct GhostToken<'brand> { /* private fields */ }
Expand description
A GhostToken<'x>
is the key to access the content of any &GhostCell<'x, _>
sharing the same brand.
Each GhostToken<'x>
is created alongside a unique brand (its lifetime), and each GhostCell<'x, T>
is associatedto one, and only one, GhostToken
at a time via this brand. The entire set of GhostCell<'x, T>
associated to agiven GhostToken<'x>
creates a pool of cells all being accessible solely through the one token they are associatedto.
The pool of GhostCell
associated to a token need not be hom*ogeneous, each may own a value of a different type.
Implementations§
source§impl<'brand> GhostToken<'brand>
impl<'brand> GhostToken<'brand>
sourcepub fn new<R, F>(fun: F) -> Rwhere for<'new_brand> F: FnOnce(GhostToken<'new_brand>) -> R,
pub fn new<R, F>(fun: F) -> Rwhere for<'new_brand> F: FnOnce(GhostToken<'new_brand>) -> R,
where for<'new_brand> F: FnOnce(GhostToken<'new_brand>) -> R,
Creates a fresh token to which GhostCell
s can be tied to later.
Due to the use of a lifetime, the GhostCell
s tied to a given token can only live within the confines of theinvocation of the fun
closure.
§Example
use ghost_cell::{GhostToken, GhostCell};let n = 12;let value = GhostToken::new(|mut token| { let cell = GhostCell::new(42); let vec: Vec<_> = (0..n).map(|_| &cell).collect(); *vec[n / 2].borrow_mut(&mut token) = 33; *cell.borrow(&token)});assert_eq!(33, value);
Trait Implementations§
impl<'brand> Send for GhostToken<'brand>
A GhostToken
is stateless, therefore it can safely be passed across threads.
impl<'brand> Sync for GhostToken<'brand>
A GhostToken
is stateless, therefore it can safely be accessed from different threads.
Auto Trait Implementations§
impl<'brand> RefUnwindSafe for GhostToken<'brand>
impl<'brand> Unpin for GhostToken<'brand>
impl<'brand> UnwindSafe for GhostToken<'brand>
Blanket Implementations§
source§impl<T> Any for T
where T: 'static + ?Sized,
impl<T> Any for T
where T: 'static + ?Sized,
source§impl<T> BorrowMut<T> for Twhere T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
where 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