Struct Event

Source
pub struct Event<A: Copy + Send, H: EventHandler<A>> { /* private fields */ }
Expand description

An event manages multiple handlers which can be registered.

§Type Parameters

  • A: The type of event arguments which are distributed to the handlers.
  • H: The type of event handlers which can be registered with this event. To allow for different types, use Box<dyn EventHandler<...>>.

Implementations§

Source§

impl<A: Copy + Send, H: EventHandler<A>> Event<A, H>

Source

pub fn new() -> Event<A, H>

Creates a new event without handlers.

Source

pub fn emit(&mut self, arg: A) -> bool

Emits an event, invoking all currently registered handlers in parallel. If all event handlers terminated without panicking, true is returned. If any event handler panics, false is returned.

§Parameters
  • arg: The event argument to dispatch.
Source

pub fn add_handler(&mut self, handler: H) -> HandlerId

Adds an event handler to notify for future events. A handler ID is returned, which can be used to identify the handler later.

§Parameters
  • handler: The event handler to register.
Source

pub fn get_handler(&self, id: HandlerId) -> Option<&H>

Gets a reference to the event handler registered under the given ID wrapped in a Some option variant. If no such handler is registered, None is returned.

§Parameters
  • id: The handler ID for which to get the associated event handler.
Source§

impl<'a, A: Copy + Send> Event<A, Box<dyn EventHandler<A> + 'a>>

Source

pub fn add_handler_boxed( &'a mut self, handler: impl EventHandler<A> + 'a, ) -> HandlerId

Adds an event handler wrapped into a box to this event. This is mainly syntactic sugar for event.add_handler(Box::new(handler)).

§Parameters
  • handler: The event handler to wrap in a box and register with this event.

Auto Trait Implementations§

§

impl<A, H> Freeze for Event<A, H>

§

impl<A, H> RefUnwindSafe for Event<A, H>

§

impl<A, H> Send for Event<A, H>

§

impl<A, H> Sync for Event<A, H>
where A: Sync, H: Sync,

§

impl<A, H> Unpin for Event<A, H>
where A: Unpin, H: Unpin,

§

impl<A, H> UnwindSafe for Event<A, H>
where A: UnwindSafe, H: UnwindSafe,

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V