Skip to main content

Context

Struct Context 

Source
pub struct Context { /* private fields */ }
Expand description

Per-component context passed to every [Component::build] call.

Carries the component’s identity and provides access to persistent local state via Context::state. State is keyed by (component_id, call_order) — the hook model — so call order within build() must be stable across frames.

Implementations§

Source§

impl Context

Source

pub fn new(id: ComponentId) -> Self

Source

pub fn component_id(&self) -> ComponentId

Source

pub fn state<T: Clone + Send + Sync + 'static>(&mut self, default: T) -> Atom<T>

Returns a persistent Atom<T> for local component state.

On first call per slot the atom is seeded with default. On subsequent frames the existing atom is returned, preserving the last value.

Source

pub fn state_permanent<T>(&mut self, key: &str, default: T) -> Atom<T>
where T: PersistValue + Clone + Send + Sync + 'static,

D008’s permanent tier, on the hook model (D114/D121): like Context::state, but the FIRST initialization reads key from the installed persist backend (falling back to default if the key is absent or its bytes are stale), and every later set writes through — the value survives a full app restart.

key is app-global: two components using the same key share the same stored value (by design — it’s a storage key, not a hook slot). With no backend installed (headless tests, or before App::launch) this behaves exactly like plain Context::state.

Uses the atom’s single on_change slot for the write-through — see Atom::set_on_change’s doc.

Source

pub fn on_cleanup(&mut self, f: impl FnOnce() + Send + 'static)

Registers a cleanup function that runs when this component unmounts.

Stored in the persistent rosace_state::cleanup_store keyed by component ID. The reconciler fires these callbacks when the component disappears from the element tree.

Auto Trait Implementations§

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.