[−][src]Struct event_emitter_rs::EventEmitter
Fields
listeners: HashMap<String, Vec<(String, Arc<dyn Fn(Vec<u8>) + Sync + Send + 'static>)>>
Implementations
impl EventEmitter
[src]
pub fn new() -> Self
[src]
pub fn on<F, T>(&mut self, event: &str, callback: F) -> String where
T: Deserialize<'de>,
F: Fn(T) + 'static + Sync + Send,
[src]
T: Deserialize<'de>,
F: Fn(T) + 'static + Sync + Send,
Adds an event listener with a callback that will get called whenever the given event is emitted. Returns the id of the newly added listener.
Example
use event_emitter::EventEmitter; let mut event_emitter = EventEmitter::new(); // This will print <"Hello world!"> whenever the <"Some event"> event is emitted // type of the value parameter for the closure MUST be specified (here we just use a throwaway `()` type) event_emitter.on("Some event", |value: ()| println!("Hello world!"));
pub fn emit<T>(&self, event: &str, value: T) where
T: Serialize,
[src]
T: Serialize,
Emits an event of the given parameters.
Example
use event_emitter::EventEmitter; let mut event_emitter = EventEmitter::new(); // Emits the <"Some event"> event and a value <"Hello programmer"> // The value can be of any type event_emitter.emit("Some event", "Hello programmer!");
pub fn remove_listener(&mut self, id_to_delete: &str) -> Option<String>
[src]
Removes an event listener with the given id
Example
use event_emitter::EventEmitter; let mut event_emitter = EventEmitter::new(); let listener_id = event_emitter.on("Some event", |value: ()| println!("Hello world!")); // Removes the listener that we just added event_emitter.remove_listener(&listener_id);
Trait Implementations
impl Default for EventEmitter
[src]
fn default() -> EventEmitter
[src]
Auto Trait Implementations
impl !RefUnwindSafe for EventEmitter
impl Send for EventEmitter
impl Sync for EventEmitter
impl Unpin for EventEmitter
impl !UnwindSafe for EventEmitter
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,