hey_listen 0.2.1

An event-dispatcher-collection offering sync, parallel, and prioritised solutions!
Documentation

ci-badge docs-badge rust 1.25+ badge crates.io version

Hey! Listen!

Hey_listen is a collection of event-dispatchers aiming to suit all needs!
Currently covering:

  • Synchronous dispatcher
  • Priority dispatcher
  • Threadpool dispatcher

Whenever applicable, dispatchers have an Rc and Arc variant.

View the examples-folder on how to use each dispatcher.

Everyone is welcome to contribute, check out the CONTRIBUTING.md for further guidance.

Example

Here is a quick example on how to use the event-dispatcher:

extern crate hey_listen;

use hey_listen::{EventDispatcher, Listener, Mutex, SyncDispatcherRequest};
use std::sync::Arc;

#[derive(Clone, Eq, Hash, PartialEq)]
enum Event {
    Variant,
}

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>::default();

    dispatcher.add_listener(Event::Variant, &listener);
    dispatcher.dispatch_event(&Event::Variant);
}

Installation

Add this to your Cargo.toml:

[dependencies]
hey_listen = "0.2"

and this to your crate's root (not needed in Rust 2018):

extern crate hey_listen;