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.
impl FireHandle
Implementation of FireHandle construction, invocation, and conversions.
Sourcepub fn new<F>(fire: F) -> Selfwhere
F: FnMut() + 'static,
pub fn new<F>(fire: F) -> Selfwhere
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.
Sourcepub unsafe fn fire(self)
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.
Sourcepub unsafe fn fire_at(addr: usize)
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 leakedBox<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
impl Clone for FireHandle
Source§fn clone(&self) -> FireHandle
fn clone(&self) -> FireHandle
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for FireHandle
Source§impl Debug for FireHandle
impl Debug for FireHandle
impl Eq for FireHandle
Source§impl<F> From<F> for FireHandlewhere
F: FnMut() + 'static,
Leaks a fire closure into a FireHandle.
impl<F> From<F> for FireHandlewhere
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§impl From<FireHandle> for usize
Extracts the raw address from a FireHandle.
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
fn from(handle: FireHandle) -> Self
Source§impl Hash for FireHandle
impl Hash for FireHandle
Source§impl Ord for FireHandle
impl Ord for FireHandle
Source§fn cmp(&self, other: &FireHandle) -> Ordering
fn cmp(&self, other: &FireHandle) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for FireHandle
impl PartialEq for FireHandle
Source§fn eq(&self, other: &FireHandle) -> bool
fn eq(&self, other: &FireHandle) -> bool
self and other values to be equal, and is used by ==.