Crate hey_listen
source ·Expand description
Hey_listen
is a collection of event-dispatchers aiming to suit all needs!
Covering synchronous, parallel, and sync-prioritised dispatching to
Closures, Enums, Structs, and every other type supporting trait
-implementation.
View the examples
on how to use each dispatcher.
Usage
Add this to your Cargo.toml
:
[dependencies]
hey_listen = "0.2"
and this to your crate’s root:
ⓘ
extern crate hey_listen;
Example
Here is a quick example on how to use the sync event-dispatcher:
extern crate hey_listen;
use hey_listen::{Listener, EventDispatcher, Mutex, SyncDispatcherRequest};
use std::sync::Arc;
#[derive(Clone, Eq, Hash, PartialEq)]
enum Event {
EventType,
}
struct ListenerStruct {}
impl Listener<Event> for ListenerStruct {
fn on_event(&mut self, event: &Event) -> Option<SyncDispatcherRequest> {
println!("I'm listening! :)");
None
}
}
fn main() {
let listener = Arc::new(Mutex::new(ListenerStruct {}));
let mut dispatcher: EventDispatcher<Event> = EventDispatcher::default();
dispatcher.add_listener(Event::EventType, &listener);
}
Re-exports
pub use self::sync::dispatcher::EventDispatcher;
pub use self::sync::parallel_dispatcher::ParallelEventDispatcher;
pub use self::sync::priority_dispatcher::PriorityEventDispatcher;
pub use self::sync::Listener;
pub use self::sync::ParallelDispatcherRequest;
pub use self::sync::ParallelListener;
pub use self::sync::SyncDispatcherRequest;
Modules
Structs
A mutual exclusion primitive useful for protecting shared data