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, useBox<dyn EventHandler<...>>
.
Implementations§
Source§impl<A: Copy + Send, H: EventHandler<A>> Event<A, H>
impl<A: Copy + Send, H: EventHandler<A>> Event<A, H>
Sourcepub fn emit(&mut self, arg: A) -> bool
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.
Sourcepub fn add_handler(&mut self, handler: H) -> HandlerId
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§impl<'a, A: Copy + Send> Event<A, Box<dyn EventHandler<A> + 'a>>
impl<'a, A: Copy + Send> Event<A, Box<dyn EventHandler<A> + 'a>>
Sourcepub fn add_handler_boxed(
&'a mut self,
handler: impl EventHandler<A> + 'a,
) -> HandlerId
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>where
A: RefUnwindSafe,
H: RefUnwindSafe,
impl<A, H> Send for Event<A, H>
impl<A, H> Sync for Event<A, H>
impl<A, H> Unpin for Event<A, H>
impl<A, H> UnwindSafe for Event<A, H>where
A: UnwindSafe,
H: UnwindSafe,
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
Mutably borrows from an owned value. Read more