pub struct Emitter<E: Event> { /* private fields */ }

Implementations§

source§

impl<E: Event + 'static> Emitter<E>

source

pub fn new() -> Self

Create a new event emitter.

source

pub async fn len(&self) -> usize

Return a count of how many subscribers have been registered.

source

pub async fn subscribe<L: Subscriber<E> + 'static>( &self, subscriber: L ) -> &Self

Register a subscriber to receive events.

source

pub async fn on<L: SubscriberFunc<E> + 'static>(&self, callback: L) -> &Self

Register a subscriber function to receive events.

source

pub async fn once<L: SubscriberFunc<E> + 'static>(&self, callback: L) -> &Self

Register a subscriber function that will unregister itself after the first event is received. This is useful for one-time event handlers.

source

pub async fn emit(&self, event: E) -> Result<E::Data>

Emit the provided event to all registered subscribers. Subscribers will be called in the order they were registered.

If a subscriber returns EventState::Stop, no further subscribers will be called. If a subscriber returns [EventState::Return], no further subscribers will be called and the provided value will be returned. If a subscriber returns EventState::Continue, the next subscriber will be called.

When complete, the provided event will be returned along with the value returned by the subscriber that returned [EventState::Return], or None if not occurred.

Auto Trait Implementations§

§

impl<E> !RefUnwindSafe for Emitter<E>

§

impl<E> Send for Emitter<E>

§

impl<E> Sync for Emitter<E>

§

impl<E> Unpin for Emitter<E>

§

impl<E> !UnwindSafe for Emitter<E>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.