Struct EventPublisher

Source
pub struct EventPublisher<E> { /* private fields */ }
Expand description

EventPublisher. Works similarly to C#’s event publishing pattern. Event handling functions are subscribed to the publisher. Whenever the publisher fires an event it calls all subscribed event handler functions. Use event::EventPublisher::::new() to construct

Implementations§

Source§

impl<E> EventPublisher<E>

Source

pub fn new() -> EventPublisher<E>

Event publisher constructor.

Source

pub fn subscribe_handler(&mut self, handler: fn(&Event<E>))

Subscribes event handler functions to the EventPublisher. INPUT: handler: fn(&Event) handler is a pointer to a function to handle an event of the type E. The function must be capable of handling references to the event type set up by the publisher, rather than the raw event itself. OUTPUT: void

Source

pub fn unsubscribe_handler(&mut self, handler: fn(&Event<E>)) -> bool

Unsubscribes an event handler from the publisher. INPUT: handler: fn(&Event) handler is a pointer to a function to handle an event of the type E. OUTPUT: bool output is a bool of whether or not the function was found in the list of subscribed event handlers and subsequently removed.

Source

pub fn publish_event(&self, event: &Event<E>)

Publishes events, pushing the &Event to all handler functions stored by the event publisher. INPUT: event: &Event Reference to the Event being pushed to all handling functions.

Auto Trait Implementations§

§

impl<E> Freeze for EventPublisher<E>

§

impl<E> RefUnwindSafe for EventPublisher<E>

§

impl<E> Send for EventPublisher<E>

§

impl<E> Sync for EventPublisher<E>

§

impl<E> Unpin for EventPublisher<E>

§

impl<E> UnwindSafe for EventPublisher<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.