WeakEvent
struct · ferroui-base · v0.5.0
struct WeakEvent<S: WeakEventSender, A: WeakEventArgs + ?Sized>
Manages subscriptions to events using weak listeners.
One instance describes one event (usually a thread-local static, see
WeakEvents). For each sender it adds a single
handler to the event, while there are subscribers, and forwards the
events to the subscribers that are still alive. The sender holds the
subscription; neither the sender nor the subscription holds the
subscribers.
Members
register
fn register<Sub, Unsub>(subscribe: Sub, unsubscribe: Unsub) -> Rc<Self>
where Sub: Fn(&S, &Rc<WeakEventHandler<A>>) -> () + 'static,
Unsub: Fn(&S, &Rc<WeakEventHandler<A>>) -> () + 'static
Registers an event through the functions that add a handler to it and remove the handler from it.
The managed original removes the handler through the sender it captured; here the removal holds the sender weakly (a strong reference would keep it alive through its own subscription), so the handler is not removed from a sender that no longer exists. It also holds the handler weakly: the handler holds the subscription, which holds the removal, and the sender owns the handler.
register_returning_unsubscribe
fn register_returning_unsubscribe<Sub>(subscribe: Sub) -> Rc<Self>
where Sub: Fn(&S, Rc<WeakEventHandler<A>>) -> Box<dyn FnOnce() -> ()> + 'static
Registers an event through a function that adds a handler to it and returns the action that removes the handler.
The action must not hold the sender strongly: the sender holds the subscription, and the subscription holds the action.
subscribe
fn subscribe(self: &Self, target: &S, subscriber: &Rc<dyn IWeakEventSubscriber<A>>)
unsubscribe
fn unsubscribe(self: &Self, target: &S, subscriber: &Rc<dyn IWeakEventSubscriber<A>>)
register_plain
fn register_plain<Sub, Unsub>(subscribe: Sub, unsubscribe: Unsub) -> Rc<Self>
where Sub: Fn(&S, &Rc<WeakEventHandler<EventArgs>>) -> () + 'static,
Unsub: Fn(&S, &Rc<WeakEventHandler<EventArgs>>) -> () + 'static
Registers an event whose handlers take the plain event arguments, through the functions that add a handler to it and remove the handler from it.
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeClassDefaultsBorrow<T>BorrowMut<T>Into<U>From<T>TryInto<U>TryFrom<U>AnyErasedDestructorIntoEither
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.