2 releases
Uses old Rust 2015
0.0.2 | Jan 25, 2015 |
---|---|
0.0.1 | Jan 25, 2015 |
#20 in #dispatcher
8KB
136 lines
EventDispatcher
A simple library to register listeners for specific events inspired by rust-emitter.
Usage example
extern crate event_dispatcher;
use event_dispatcher::{Event, Listener, Dispatcher, Dispatchable};
struct TestEvent {
stopped: bool,
data: String
}
impl TestEvent {
pub fn new(event_data: String) -> TestEvent {
TestEvent {
stopped: false,
data: event_data
}
}
}
impl Event<TestEvent> for TestEvent {
fn is_propagation_stopped(&self) -> bool{
self.stopped
}
fn stop_propagation(&mut self){
self.stopped = true;
}
}
// the listener
fn event_test(event: &TestEvent) {
println!("called \"event_test\"");
}
fn main() {
let event = TestEvent::new("my_event".to_string());
let mut dispatcher = Dispatcher::new();
dispatcher.add_listener(&event, Listener::new(my_event_test));
dispatcher.dispatch(&event);
}