ariel_os::cell

Struct StaticCell

pub struct StaticCell<T> { /* private fields */ }
Expand description

Statically allocated, initialized at runtime cell.

It has two states: “empty” and “full”. It is created “empty”, and obtaining a reference to the contents permanently changes it to “full”. This allows that reference to be valid forever.

If your value can be initialized as a const value, consider using ConstStaticCell instead if you only need to take the value at runtime.

See the crate-level docs for usage.

Implementations§

§

impl<T> StaticCell<T>

pub const fn new() -> StaticCell<T>

Available on crate feature threading only.

Create a new, empty StaticCell.

It can be initialized at runtime with StaticCell::init() or similar methods.

pub fn init(&'static self, val: T) -> &'static mut T

Available on crate feature threading only.

Initialize the StaticCell with a value, returning a mutable reference to it.

Using this method, the compiler usually constructs val in the stack and then moves it into the StaticCell. If T is big, this is likely to cause stack overflows. Considering using StaticCell::init_with instead, which will construct it in-place inside the StaticCell.

§Panics

Panics if this StaticCell is already full.

pub fn init_with(&'static self, val: impl FnOnce() -> T) -> &'static mut T

Available on crate feature threading only.

Initialize the StaticCell with the closure’s return value, returning a mutable reference to it.

The advantage over StaticCell::init is that this method allows the closure to construct the T value in-place directly inside the StaticCell, saving stack space.

§Panics

Panics if this StaticCell is already full.

pub fn uninit(&'static self) -> &'static mut MaybeUninit<T>

Available on crate feature threading only.

Return a mutable reference to the uninitialized memory owned by the StaticCell.

Using this method directly is not recommended, but it can be used to construct T in-place directly in a guaranteed fashion.

§Panics

Panics if this StaticCell is already full.

pub fn try_init(&'static self, val: T) -> Option<&'static mut T>

Available on crate feature threading only.

Try initializing the StaticCell with a value, returning a mutable reference to it.

If this StaticCell is already full, it returns None.

Using this method, the compiler usually constructs val in the stack and then moves it into the StaticCell. If T is big, this is likely to cause stack overflows. Considering using StaticCell::try_init_with instead, which will construct it in-place inside the StaticCell.

Will only return a Some(&’static mut T) when the StaticCell was not yet initialized.

pub fn try_init_with( &'static self, val: impl FnOnce() -> T, ) -> Option<&'static mut T>

Available on crate feature threading only.

Try initializing the StaticCell with the closure’s return value, returning a mutable reference to it.

If this StaticCell is already full, it returns None.

The advantage over StaticCell::init is that this method allows the closure to construct the T value in-place directly inside the StaticCell, saving stack space.

pub fn try_uninit(&'static self) -> Option<&'static mut MaybeUninit<T>>

Available on crate feature threading only.

Try returning a mutable reference to the uninitialized memory owned by the StaticCell.

If this StaticCell is already full, it returns None.

Using this method directly is not recommended, but it can be used to construct T in-place directly in a guaranteed fashion.

Trait Implementations§

§

impl<T> Send for StaticCell<T>

§

impl<T> Sync for StaticCell<T>

Auto Trait Implementations§

§

impl<T> !Freeze for StaticCell<T>

§

impl<T> !RefUnwindSafe for StaticCell<T>

§

impl<T> Unpin for StaticCell<T>
where T: Unpin,

§

impl<T> UnwindSafe for StaticCell<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

§

const WITNESS: W = W::MAKE

A constant of the type witness
§

impl<T> Identity for T
where T: ?Sized,

§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V