Emitter

Struct Emitter 

Source
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::Continue, the next subscriber will be called.

Auto Trait Implementations§

§

impl<E> Freeze for Emitter<E>

§

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