FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

    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.

    View source

    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.

    Source

    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.

    Source

    subscribe

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

    Source

    unsubscribe

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

    Source

    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.

    Source

    Trait implementations

    • Send
    • Sync
    • Freeze
    • UnsafeUnpin
    • Unpin
    • UnwindSafe
    • RefUnwindSafe
    • ClassDefaults
    • Borrow<T>
    • BorrowMut<T>
    • Into<U>
    • From<T>
    • TryInto<U>
    • TryFrom<U>
    • Any
    • ErasedDestructor
    • IntoEither

    Availability

    Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.