Skip to main content

WeakEvent

Struct WeakEvent 

Source
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>

Source

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.

Source

pub 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.

Source

pub fn subscribe( &self, target: &S, subscriber: &Rc<dyn IWeakEventSubscriber<A>>, )

Source

pub fn unsubscribe( &self, target: &S, subscriber: &Rc<dyn IWeakEventSubscriber<A>>, )

Source§

impl<S: WeakEventSender> WeakEvent<S, EventArgs>

Source

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>
where Weak<WeakEvent<S, A>>: Unpin, 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()>>: Unpin, RefCell<SubscriptionTable<S, A>>: Unpin, A: ?Sized,

§

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> 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> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.