event_dispatcher 0.0.2

A simple library to register listeners (with priority) for specific events inspired by rust-emitter
docs.rs failed to build event_dispatcher-0.0.2
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.

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);
}