pub struct Mailbox<T> { /* private fields */ }Expand description
Single-threaded message queue bridging async browser callbacks into the render loop — the standard wasm integration shape every app was inventing (fetch results, WebSocket messages, file reads):
- Create one
Mailbox<Msg>per message stream; clone it into yourspawn_localfutures and JS callbacks. - After
start_with_configreturns, callMailbox::set_handlewith theWebHandleso pushes wake the host. Mailbox::pushfrom callbacks — it queues the value and requests a redraw.Mailbox::draininApp::before_buildand fold the messages into app state; the frame being built sees them.
Clone is a cheap Rc bump (wasm is single-threaded; this type is
deliberately not Send). Pushes before set_handle are queued and
delivered on the first frame after the host starts.
Implementations§
Source§impl<T> Mailbox<T>
impl<T> Mailbox<T>
Sourcepub fn set_handle(&self, handle: WebHandle)
pub fn set_handle(&self, handle: WebHandle)
Attach the host’s redraw handle (the WebHandle returned by
start_with_config) so subsequent pushes wake the render
loop. Idempotent; replaces any previous handle.
Sourcepub fn push(&self, value: T)
pub fn push(&self, value: T)
Queue a message and request a redraw (when a handle is
attached). Call from spawn_local futures and JS event
callbacks.
Trait Implementations§
Auto Trait Implementations§
impl<T> !RefUnwindSafe for Mailbox<T>
impl<T> !Send for Mailbox<T>
impl<T> !Sync for Mailbox<T>
impl<T> !UnwindSafe for Mailbox<T>
impl<T> Freeze for Mailbox<T>
impl<T> Unpin for Mailbox<T>
impl<T> UnsafeUnpin for Mailbox<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.