Crate hey_listen [] [src]

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.0"
parking_lot = "^0.5"

and this to your crate's root:

This example is not tested
extern crate hey_listen;
extern crate parking_lot;

Example

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

extern crate hey_listen;
extern crate parking_lot;

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

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

Structs

EventDispatcher

Owns a map of all listened event-variants, Weak-references to their listeners and Fns.

ParallelEventDispatcher

Owns a map of all listened event-variants, Weak-references to their listeners and Fns.

PriorityEventDispatcher

Owns a map of all listened event-variants, Weak-references to their listeners and Fns. Opposed to EventListener, this structure utilises one BTreeMap per event-type to order listeners by a given priority-level.

Enums

BuildError

Errors for ThreadPool-building related failures.

ParallelDispatcherRequest

An enum returning a request from a Listener to its async event-dispatcher.

SyncDispatcherRequest

An enum returning a request from a listener to its sync event-dispatcher. A request will be processed by the event-dispatcher depending on the variant:

Traits

Listener

Every event-receiver needs to implement this trait in order to receive dispatched events. T being the type you use for events, e.g. an Enum.

ParallelListener

Every event-receiver needs to implement this trait in order to receive dispatched events. T being the type you use for events, e.g. an Enum.