pub struct HookContext { /* private fields */ }Expand description
Manages hook state across render cycles for a DynamicNode.
Stores boxed Any values keyed by hook call order, enabling use_signal
and similar hooks to persist state between re-renders of the same
dynamic node.
Implements Copy for ergonomic use; all copies share the same underlying state.
SAFETY: The inner pointer is allocated via Box::leak and lives for the
entire program. This is safe in single-threaded WASM contexts where no
concurrent access can occur.
Implementations§
Source§impl HookContext
Implementation of hook context lifecycle and hook index management.
impl HookContext
Implementation of hook context lifecycle and hook index management.
Sourcepub fn leak_mut(&self) -> &'static mut HookContextInner
pub fn leak_mut(&self) -> &'static mut HookContextInner
Returns a mutable reference to the inner hook context state by going
through usize intermediate conversion.
§Returns
&'static mut HookContextInner- A mutable reference to the inner state.
Sourcepub fn reset_hook_index(&mut self)
pub fn reset_hook_index(&mut self)
Resets the hook index for a new render cycle.
Sets the hook index back to 0 so that subsequent hook calls
re-associate with their stored state by call order.
Sourcepub fn set_arm_changed(&mut self, changed: bool)
pub fn set_arm_changed(&mut self, changed: bool)
Notifies the hook context that a match arm is being entered.
Toggles the arm_changed flag; if it differs from the previous value,
the hooks array is cleared to prevent signal leakage between arms.
§Arguments
bool- The new arm changed state.
Trait Implementations§
Source§impl Clone for HookContext
Clones the hook context, sharing the same inner state.
impl Clone for HookContext
Clones the hook context, sharing the same inner state.
Source§impl Debug for HookContext
impl Debug for HookContext
Source§impl Default for HookContext
Provides a default empty hook context.
impl Default for HookContext
Provides a default empty hook context.
Source§impl From<HookContext> for usize
Implementation of From trait for converting HookContext into usize address.
impl From<HookContext> for usize
Implementation of From trait for converting HookContext into usize address.
Source§impl From<usize> for HookContext
Implementation of From trait for converting usize address into HookContext.
impl From<usize> for HookContext
Implementation of From trait for converting usize address into HookContext.
Source§fn from(address: usize) -> Self
fn from(address: usize) -> Self
Converts a memory address into a HookContext handle.
§Arguments
usize- The memory address previously obtained fromHookContextconversion.
§Returns
HookContext- A hook context handle wrapping the pointer at the given address.
§Safety
- The address is guaranteed to be a valid
HookContextInnerinstance that was previously converted from a hook context handle and is managed by the runtime.
impl Copy for HookContext
Copies the hook context, sharing the same inner state.
A HookContext is just a raw pointer; copying it is a trivial bitwise copy.