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 associated to one, and only one, GhostToken at a time via this brand. The entire set of GhostCell<'x, T> associated to a given GhostToken<'x> creates a pool of cells all being accessible solely through the one token they are associated to.

The pool of GhostCell associated to a token need not be homogeneous, each may own a value of a different type.

Implementations

Creates a fresh token to which GhostCells can be tied to later.

Due to the use of a lifetime, the GhostCells tied to a given token can only live within the confines of the invocation 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

A GhostToken is stateless, therefore it can safely be passed across threads.

A GhostToken is stateless, therefore it can safely be accessed from different threads.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.