pub struct Publisher { /* private fields */ }Expand description
Publishes all Events to all subscribed Handlers that accept Events of that type
§Examples
use gawk::{Event, Handler, Publisher};
#[derive(Copy, Clone)]
struct GamePaused {}
impl Event for GamePaused {}
let mut publisher = Publisher::default();
let pause_handler = Handler::new(|_event: GamePaused| println!("Game paused"));
let pause_handler_id = publisher.subscribe(pause_handler);
publisher.publish(GamePaused {});
publisher.unsubscribe(pause_handler_id);
Implementations§
Source§impl Publisher
impl Publisher
Sourcepub fn subscribe<T>(&mut self, handler: T) -> usizewhere
T: DynHandle + 'static,
pub fn subscribe<T>(&mut self, handler: T) -> usizewhere
T: DynHandle + 'static,
Subscribe a handler to the publisher so that the handler receives all published events.
Returns the ID needed to unsubscribe the handler.
Sourcepub fn unsubscribe(&mut self, id: usize)
pub fn unsubscribe(&mut self, id: usize)
Remove a handler from the publisher so that it stops receiving events
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Publisher
impl RefUnwindSafe for Publisher
impl Send for Publisher
impl Sync for Publisher
impl Unpin for Publisher
impl UnwindSafe for Publisher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more