Struct singleton_cell::SCell
source · [−]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
sourceimpl<Key: ?Sized, T: ?Sized> SCell<Key, T>
impl<Key: ?Sized, T: ?Sized> SCell<Key, T>
sourcepub fn from_mut(t: &mut T) -> &mut Self
pub fn from_mut(t: &mut T) -> &mut Self
Convert a unique reference to a value to a unique reference to this cell type. These two types are equivalent when accessed uniquely.
sourcepub fn get_mut(&mut self) -> &mut T
pub fn get_mut(&mut self) -> &mut T
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.
sourceimpl<Key: ?Sized, T> SCell<Key, T>
impl<Key: ?Sized, T> SCell<Key, T>
sourcepub fn new(t: T) -> Self
pub fn new(t: T) -> Self
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.
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Destruct the SCell and access the inner data.
This requires ownership of the SCell and hence guarantees no simultaneous access.
sourceimpl<Key: ?Sized, T> SCell<Key, [T]>
impl<Key: ?Sized, T> SCell<Key, [T]>
sourcepub fn as_slice_of_cells(&self) -> &[SCell<Key, T>]
pub fn as_slice_of_cells(&self) -> &[SCell<Key, T>]
Returns a slice of cells from a cell of a slice.
sourceimpl<Key: Singleton + ?Sized, T: ?Sized> SCell<Key, T>
impl<Key: Singleton + ?Sized, T: ?Sized> SCell<Key, T>
sourcepub fn borrow<'a>(&'a self, _: impl Exists<&'a Key>) -> &'a T where
Key: 'a,
pub fn borrow<'a>(&'a self, _: impl Exists<&'a Key>) -> &'a T where
Key: 'a,
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.
sourcepub fn borrow_mut<'a>(&'a self, _: impl Exists<&'a mut Key>) -> &'a mut T where
Key: 'a,
pub fn borrow_mut<'a>(&'a self, _: impl Exists<&'a mut Key>) -> &'a mut T where
Key: 'a,
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.
sourceimpl<Key: Singleton + ?Sized, T> SCell<Key, T>
impl<Key: Singleton + ?Sized, T> SCell<Key, T>
Trait Implementations
impl<Key, T: Send> Send for SCell<Key, T>
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
impl<Key, T: Send + Sync> Sync for SCell<Key, T>
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
impl<Key, T> !RefUnwindSafe for SCell<Key, T>
impl<Key: ?Sized, T: ?Sized> Unpin for SCell<Key, T> where
T: Unpin,
impl<Key: ?Sized, T: ?Sized> UnwindSafe for SCell<Key, T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more