Struct singleton_cell::SCell[][src]

#[repr(transparent)]
pub struct SCell<Key: ?Sized, T: ?Sized> { /* fields omitted */ }
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.

Unique access to this cell guarantees that no other accesses to it can be performed simultaneously.

Get a raw pointer to this cell’s data

Construct a new SCell from underlying data.

Destruct the SCell and access the inner data.

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.

Safety to borrow is guaranteed by the immutable borrow to the singleton key for this cell.

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

Safety to borrow mutably is guaranteed by the mutable borrow to the singleton key for this cell.

Replace the value behind this cell with a new one.

This requires unique access to the token in order to ensure there are no other active borrows we could be invalidating.

Replace the value behind this cell with the default one.

This requires unique access to the token in order to ensure there are no other active borrows we could be invalidating.

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

Performs the conversion.

Performs the conversion.

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.