pub struct WeakEvent<S: WeakEventSender, A: WeakEventArgs + ?Sized> { /* private fields */ }Expand description
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.
Implementations§
Source§impl<S: WeakEventSender, A: WeakEventArgs + ?Sized> WeakEvent<S, A>
impl<S: WeakEventSender, A: WeakEventArgs + ?Sized> WeakEvent<S, A>
Sourcepub 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,
pub 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.
Sourcepub fn register_returning_unsubscribe<Sub>(subscribe: Sub) -> Rc<Self>
pub fn register_returning_unsubscribe<Sub>(subscribe: Sub) -> Rc<Self>
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.
pub fn subscribe( &self, target: &S, subscriber: &Rc<dyn IWeakEventSubscriber<A>>, )
pub fn unsubscribe( &self, target: &S, subscriber: &Rc<dyn IWeakEventSubscriber<A>>, )
Source§impl<S: WeakEventSender> WeakEvent<S, EventArgs>
impl<S: WeakEventSender> WeakEvent<S, EventArgs>
Sourcepub 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,
pub 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.
Auto Trait Implementations§
impl<S, A> !Freeze for WeakEvent<S, A>
impl<S, A> !RefUnwindSafe for WeakEvent<S, A>
impl<S, A> !Send for WeakEvent<S, A>
impl<S, A> !Sync for WeakEvent<S, A>
impl<S, A> !UnwindSafe for WeakEvent<S, A>
impl<S, A> Unpin for WeakEvent<S, A>
impl<S, A> UnsafeUnpin for WeakEvent<S, A>where
Weak<WeakEvent<S, A>>: UnsafeUnpin,
Box<dyn Fn(&S, Rc<dyn for<'s, 'r, 'a> Fn(Option<&'s (dyn Any + 'static)>, &'r <A as WeakEventArgs>::Args<'a>)>) -> Box<dyn FnOnce()>>: UnsafeUnpin,
RefCell<SubscriptionTable<S, A>>: UnsafeUnpin,
A: ?Sized,
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
Source§impl<T> ClassDefaults for Twhere
T: ?Sized,
impl<T> ClassDefaults for Twhere
T: ?Sized,
Source§fn static_constructor()
fn static_constructor()
affects_render, metadata
overrides). Read more