Skip to main content

FireHandle

Struct FireHandle 

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

A handle to a leaked FnMut() closure, stored as the closure’s heap address.

The closure is double-boxed (Box<Box<dyn FnMut()>>) and leaked, so its memory outlives any FireHandle copy and can be safely invoked from any context via the raw pointer. The handle is Copy because it only holds the address — repeated invocations on captured copies all resolve to the same underlying closure.

This type replaces the inline Box::leak(... as *mut Box<dyn FnMut()> as usize) pattern that was used by watch!/computed! macros and the virtual list component, encapsulating the unsized coercion, double-boxing, and raw pointer arithmetic behind From/Into conversions and a dedicated fire method.

Implementations§

Source§

impl FireHandle

Implementation of FireHandle construction, invocation, and conversions.

Source

pub fn new<F>(fire: F) -> Self
where F: FnMut() + 'static,

Leaks the given closure and returns a handle pointing to its heap address.

The closure is double-boxed (Box<Box<dyn FnMut()>>) and leaked so the inner box’s address remains stable for the lifetime of the program. The address is captured as a usize and wrapped in a FireHandle.

§Arguments
  • F: FnMut() + 'static - The fire closure to leak.
§Returns
  • FireHandle - A handle holding the leaked closure’s address.
Source

pub unsafe fn fire(self)

Invokes the closure pointed to by this handle.

Takes self by value because FireHandle: Copy — repeated invocations on a single captured handle each copy the address and operate on the same underlying closure.

§Safety

The handle must come from FireHandle::new (or From) and the underlying boxed closure must still be live.

Source

pub unsafe fn fire_at(addr: usize)

Invokes the closure stored at the given address.

This is the static counterpart of fire for call sites that have only the raw usize address (e.g., macro-generated code that captures the address by move into a subscribe closure).

§Arguments
  • usize - The address of a leaked Box<dyn FnMut()>.
§Safety

addr must come from a valid FireHandle produced by new (or From) and the underlying boxed closure must still be live.

Trait Implementations§

Source§

impl Clone for FireHandle

Source§

fn clone(&self) -> FireHandle

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for FireHandle

Source§

impl Debug for FireHandle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for FireHandle

Source§

impl<F> From<F> for FireHandle
where F: FnMut() + 'static,

Leaks a fire closure into a FireHandle.

This is the canonical Into path used by watch!/computed! macros and the virtual list component to obtain a FireHandle from a closure.

Source§

fn from(fire: F) -> Self

Leaks this closure and stores its address in the returned handle.

§Returns
  • FireHandle - A handle holding the leaked closure’s address.
Source§

impl From<FireHandle> for usize

Extracts the raw address from a FireHandle.

This is used by macro-generated code that needs to capture the address (a Copy type) into FnMut() + 'static subscribe closures.

Source§

fn from(handle: FireHandle) -> Self

Returns the leaked closure’s heap address.

§Returns
  • usize - The address held by this handle.
Source§

impl Hash for FireHandle

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for FireHandle

Source§

fn cmp(&self, other: &FireHandle) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for FireHandle

Source§

fn eq(&self, other: &FireHandle) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for FireHandle

Source§

fn partial_cmp(&self, other: &FireHandle) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for FireHandle

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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