Struct hey_listen::rc::dispatcher::Dispatcher [−][src]
In charge of parallel dispatching to all listeners.
Implementations
impl<T> Dispatcher<T> where
T: PartialEq + Eq + Hash + Clone + Sized + 'static,
[src]
T: PartialEq + Eq + Hash + Clone + Sized + 'static,
#[must_use]pub fn new() -> Self
[src]
Create a new blocking dispatcher.
pub fn add_listener<D: Listener<T> + Sized + 'static>(
&mut self,
event_key: T,
listener: D
)
[src]
&mut self,
event_key: T,
listener: D
)
Adds a Listener
to listen for an event_key
.
Note: If your Enum
owns fields you need to consider implementing
the Hash
- and PartialEq
-trait if you want to ignore fields,
see second example for an implementation-suggestion.
Examples
Adding a Listener
to the dispatcher:
use hey_listen::rc::{ Listener, Dispatcher, DispatcherRequest, }; #[derive(Clone, Eq, Hash, PartialEq)] enum Event { EventType, } struct ListenerStruct; impl Listener<Event> for ListenerStruct { fn on_event(&self, event: &Event) -> Option<DispatcherRequest> { None } } let listener = ListenerStruct; let mut dispatcher: Dispatcher<Event> = Dispatcher::new(); dispatcher.add_listener(Event::EventType, listener);
Declaring your own Hash
- and PartialEq
-trait to bypass
hashing on fields:
use std::hash::{Hash, Hasher}; use std::mem::discriminant; #[derive(Clone)] enum Event { TestVariant(i32), } impl Hash for Event { fn hash<H: Hasher>(&self, _state: &mut H) {} } impl PartialEq for Event { fn eq(&self, other: &Event) -> bool { discriminant(self) == discriminant(other) } } impl Eq for Event {}
pub fn dispatch_event(&mut self, event_identifier: &T)
[src]
All Listener
s listening to a passed event_identifier
will be called via their implemented on_event
-method.
Listener
s returning an Option
wrapping DispatcherRequest
with DispatcherRequest::StopListening
will cause them
to be removed from the event-dispatcher.
Auto Trait Implementations
impl<T> !RefUnwindSafe for Dispatcher<T>
impl<T> !Send for Dispatcher<T>
impl<T> !Sync for Dispatcher<T>
impl<T> Unpin for Dispatcher<T> where
T: Unpin,
T: Unpin,
impl<T> !UnwindSafe for Dispatcher<T>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,