Skip to main content

MaybeEngineCell

Struct MaybeEngineCell 

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

A Sync wrapper that may or may not contain a value.

§When to choose this vs EngineCell

Use this when the global state has a clear “not yet installed” or “already torn down” state. Access is gated on the inner Option being Some, so all the try_* accessors return Option<...>, matching core::reactive::hook::try_get_current’s wording.

§Field access rule

Same as EngineCell: inner is reached only through the hand-written get_inner / set_inner accessors; the struct-literal escape hatch is reserved for the new / default constructors.

Implementations§

Source§

impl<T> MaybeEngineCell<T>

Accessor implementations for MaybeEngineCell.

Source

pub fn get_inner(&self) -> &UnsafeCell<Option<T>>

Returns a shared reference to the backing UnsafeCell<Option<T>>.

Source

pub fn set_inner(&mut self, val: UnsafeCell<Option<T>>) -> UnsafeCell<Option<T>>

Replaces the backing storage with val, returning the previous UnsafeCell<Option<T>>.

§Arguments
  • val: UnsafeCell<Option<T>> - The new backing storage to install.
§Returns
  • UnsafeCell<Option<T>> - The previous backing storage.

Implemented via core::mem::replace. MaybeEngineCell<T> carries the implicit Sized bound (it is T: Sized here because Option<T> is Sized only when T is); mem::replace therefore applies. The returned previous backing storage is the caller’s responsibility to drop.

Note: set_inner is currently unused by the rest of the module (the try_* paths go straight through raw pointer reads/writes). It is kept here as the Lombok-shaped counterpart for parity with EngineCell::get_inner, in case future code wants to swap the whole backing storage.

Source§

impl<T> MaybeEngineCell<T>

Constructor + accessors for MaybeEngineCell.

Source

pub const fn new() -> Self

Creates an empty cell.

Struct literal is permitted by the field-access rule for the constructor only.

Source

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

If the cell contains a value, returns a shared reference to it.

Source

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

If the cell contains a value, returns a mutable reference to it.

§Safety

Exclusivity rules from EngineCell::get_mut apply - no other borrow on the same cell may be alive.

Source

pub fn try_set(&self, value: T) -> Result<(), T>

Installs value into the cell. Returns Err(value) if the cell is already populated; the caller may then retry or drop it.

Reads through get_inner to inspect the current state without aliasing, then writes through UnsafeCell::get raw pointer.

Source

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

Removes and returns the contained value, leaving the cell empty.

Source

pub fn try_replace(&self, value: T) -> Option<T>

Replaces the contained value, returning the old one.

Trait Implementations§

Source§

impl<T> Default for MaybeEngineCell<T>

Default impl for MaybeEngineCell.

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T> Sync for MaybeEngineCell<T>

Marker that MaybeEngineCell<T> is safe to share across the wasm main thread under single-threaded access.

Auto Trait Implementations§

§

impl<T> !Freeze for MaybeEngineCell<T>

§

impl<T> !RefUnwindSafe for MaybeEngineCell<T>

§

impl<T> Send for MaybeEngineCell<T>
where T: Send,

§

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

§

impl<T> UnsafeUnpin for MaybeEngineCell<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for MaybeEngineCell<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<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.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more