Skip to main content

Event

Struct Event 

Source
pub struct Event<A>
where A: ?Sized,
{ /* private fields */ }
Expand description

A multicast event of a model object: the equivalent of a managed event member on a type that is not part of the class hierarchy.

Handlers are identified by the token returned from add. Raising works on a snapshot, so handlers may add or remove handlers.

Implementations§

Source§

impl<A> Event<A>
where A: ?Sized,

Source

pub fn new() -> Event<A>

Source

pub fn with_shared_ids(ids: Rc<Cell<u64>>) -> Event<A>

An event whose handler tokens come from ids, a counter shared with other handler lists (see HandlerList::with_shared_ids).

Source

pub fn with_ordered_ids() -> Event<A>

An event whose handler tokens come from the counter of the process (see HandlerList::with_ordered_ids).

Source

pub fn snapshot(&self) -> HandlerSnapshot<dyn Fn(&A)>

The current handlers with their tokens; later changes do not affect it.

Source

pub fn add(&self, handler: Rc<dyn Fn(&A)>) -> u64

Adds a handler; returns the token that removes it.

Source

pub fn remove(&self, token: u64) -> bool

Removes a handler. Returns false if the token is unknown.

Source

pub fn has_handlers(&self) -> bool

Whether any handler is subscribed.

Source

pub fn handler_count(&self) -> usize

The number of subscribed handlers.

Source

pub fn raise(&self, args: &A)

Invokes the handlers.

Trait Implementations§

Source§

impl<A> Default for Event<A>
where A: ?Sized,

Source§

fn default() -> Event<A>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<A> !Freeze for Event<A>

§

impl<A> !RefUnwindSafe for Event<A>

§

impl<A> !Send for Event<A>

§

impl<A> !Sync for Event<A>

§

impl<A> !UnwindSafe for Event<A>

§

impl<A> Unpin for Event<A>
where HandlerList<dyn Fn(&A)>: Unpin, A: ?Sized,

§

impl<A> UnsafeUnpin for Event<A>
where HandlerList<dyn Fn(&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.