#[repr(transparent)]
pub struct SCell<Key: ?Sized, T: ?Sized> { /* private fields */ }
Expand description

SCell, or SingletonCell provides an interface of a Ghost Cell, where the Key is allowed to be any singleton, rather than a particular token type.

As a result, the uniqueness for the key can be provided by any means, and the key type / resulting cell may also be ’static for long-lived data structures

Implementations

Convert a unique reference to a value to a unique reference to this cell type. These two types are equivalent when accessed uniquely.

Uniquely borrow this cell in order to access T mutably.

This requires unique access to self, rather than using a key. For shared access, see the borrow_mut method instead.

Because this requires unique access to self, and all other borrows require at least a shared reference, unique access to the underlying data is safe.

Get a raw pointer to this cell’s data.

Construct a new SCell from underlying data.

See also SCell::from_mut which can be used when the usage of SCell is only within the scope of mutable borrows of the data.

Destruct the SCell and access the inner data.

This requires ownership of the SCell and hence guarantees no simultaneous access.

Returns a slice of cells from a cell of a slice.

Borrow the data underlying this cell, using a reference to the singleton Key type.

This is safe because any mutable borrow must either come from a mutable reference to this cell, or a mutable reference to the key, which cannot exist since this takes a shared borrow of both this cell and the key.

Mutably borrow the data underlying this cell, using a mutable reference to the singleton Key type.

This is safe because it requires a unique borrow of the key, and a shared borrow of self, which prevents all other borrows into the data.

Replace the value behind this cell with a new one.

This mutates the data and hence requires unique access to the key to ensure that no borrows are invalidated.

Replace the value behind this cell with the default one.

This mutates the data and so requires unique access to the key to ensure that no borrows are invalidated.

Trait Implementations

An owned SCell is equivalent to its underlying value, and can be converted between them, so SCell<Key, T> is Send if and only if T is Send

A shared reference to SCell can access the underlying value both via shared reference, and via mutable reference, so it can be Sync only if T is both Sync and Send.

SCell does not otherwise put any constraints on Sync since all shared usages must use references to the Key, which must be sent between threads as normal.

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.