diff options
author | 2019-11-22 22:14:04 +0100 | |
---|---|---|
committer | 2019-11-22 22:14:04 +0100 | |
commit | fa227255b02adbbfa99801a7baaa4d6d387f7302 (patch) | |
tree | 1b9b4c97a6b6a054ff73cd69ac9b1493f50392c3 /web/src/bus.rs | |
parent | 048909b45dfecef73bfacf3b5aa67462470ccca2 (diff) | |
download | iced-fa227255b02adbbfa99801a7baaa4d6d387f7302.tar.gz iced-fa227255b02adbbfa99801a7baaa4d6d387f7302.tar.bz2 iced-fa227255b02adbbfa99801a7baaa4d6d387f7302.zip |
Write docs for `iced_web`
Diffstat (limited to 'web/src/bus.rs')
-rw-r--r-- | web/src/bus.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/web/src/bus.rs b/web/src/bus.rs index b4fd67c7..09908679 100644 --- a/web/src/bus.rs +++ b/web/src/bus.rs @@ -2,6 +2,12 @@ use crate::Instance; use std::rc::Rc; +/// A publisher of messages. +/// +/// It can be used to route messages back to the [`Application`]. +/// +/// [`Application`]: trait.Application.html +#[allow(missing_debug_implementations)] #[derive(Clone)] pub struct Bus<Message> { publish: Rc<Box<dyn Fn(Message, &mut dyn dodrio::RootRender)>>, @@ -11,7 +17,7 @@ impl<Message> Bus<Message> where Message: 'static, { - pub fn new() -> Self { + pub(crate) fn new() -> Self { Self { publish: Rc::new(Box::new(|message, root| { let app = root.unwrap_mut::<Instance<Message>>(); @@ -21,10 +27,17 @@ where } } + /// Publishes a new message for the [`Application`]. + /// + /// [`Application`]: trait.Application.html pub fn publish(&self, message: Message, root: &mut dyn dodrio::RootRender) { (self.publish)(message, root); } + /// Creates a new [`Bus`] that applies the given function to the messages + /// before publishing. + /// + /// [`Bus`]: struct.Bus.html pub fn map<B>(&self, mapper: Rc<Box<dyn Fn(B) -> Message>>) -> Bus<B> where B: 'static, |