StaticCell

Struct StaticCell 

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

A no_std init-once container designed for the oveRTOS lifecycle.

  • const fn new() — usable in static declarations
  • init() — set value (panics if already set)
  • get() — get reference (panics if not set)
  • try_get() — non-panicking variant
  • shutdown() — drop contained value, mark uninitialized

§Safety contract

init() and shutdown() must be called single-threaded (framework lifecycle guarantee: on_init / on_shutdown). Between init and shutdown the value is immutable — no data race is possible.

Implementations§

Source§

impl<T> StaticCell<T>

Source

pub const fn new() -> Self

Create an empty cell. Usable in static declarations.

Source

pub fn init(&self, val: T)

Initialize the cell with val.

§Panics

Panics if the cell is already initialized.

§Safety contract

Must be called single-threaded (e.g. in on_init).

Source

pub fn get(&self) -> &T

Get a reference to the contained value.

§Panics

Panics if the cell has not been initialized.

Source

pub fn try_init(&self, val: T) -> Result<(), T>

Try to initialize the cell. Returns Err(val) if already initialized, so the caller doesn’t lose the value.

§Safety contract

Same as init() — must be called single-threaded.

Source

pub fn try_get(&self) -> Option<&T>

Try to get a reference, returning None if not initialized.

Source

pub fn shutdown(&self)

Drop the contained value and mark the cell as uninitialized.

Idempotent — no-op if already empty.

§Safety contract

Must be called single-threaded (e.g. in on_shutdown).

Trait Implementations§

Source§

impl<T> Deref for StaticCell<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.
Source§

impl<T: Send> Send for StaticCell<T>

Source§

impl<T: Send + Sync> 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.

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.