1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
//! `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`: //! //! ```toml //! [dependencies] //! hey_listen = "0.5" //! ``` //! //! # Example //! Here is a quick example on how to use the sync event-dispatcher: //! //! ```rust //! use hey_listen::sync::{ //! ParallelDispatcher, ParallelListener, ParallelDispatchResult, //! }; //! //! #[derive(Clone, Eq, Hash, PartialEq)] //! enum Event { //! EventType, //! } //! //! struct ListenerStruct; //! //! impl ParallelListener<Event> for ListenerStruct { //! fn on_event(&self, event: &Event) -> Option<ParallelDispatchResult> { //! println!("I'm listening! :)"); //! //! None //! } //! } //! //! let listener = ListenerStruct; //! let mut dispatcher: ParallelDispatcher<Event> = ParallelDispatcher::new(8).expect("Could not construct threadpool"); //! //! dispatcher.add_listener(Event::EventType, listener); //! //! ``` //! [`examples`]: https://github.com/Lakelezz/hey_listen/tree/master/examples #![deny(rust_2018_idioms)] #![deny(clippy::all)] #![deny(clippy::pedantic)] #![deny(clippy::nursery)] #![deny(clippy::cargo)] #![deny(missing_docs)] #[cfg(feature = "blocking")] /// The blocking dispatcher module. pub mod rc; #[cfg(any(feature = "parallel", feature = "async"))] /// The parallel/async dispatcher module. pub mod sync; #[cfg(any(feature = "parallel", feature = "async"))] pub use parking_lot::{Mutex, RwLock}; #[cfg(feature = "parallel")] use rayon::ThreadPoolBuildError; /// `hey_listen`'s Error collection. #[derive(Debug)] /// As long as there are no other errors, keep it locked away. #[cfg(feature = "parallel")] pub enum Error { /// Error when building a threadpool fails. ThreadPoolBuilder(String), } #[cfg(feature = "parallel")] impl From<ThreadPoolBuildError> for Error { fn from(error: ThreadPoolBuildError) -> Self { Self::ThreadPoolBuilder(error.to_string()) } }