From 98160406f714728afe718f305bf9d12be1676b2d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 8 Dec 2019 08:21:26 +0100 Subject: Allow listening to runtime events in subscriptions --- native/src/subscription.rs | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 native/src/subscription.rs (limited to 'native/src/subscription.rs') diff --git a/native/src/subscription.rs b/native/src/subscription.rs new file mode 100644 index 00000000..5fa026a2 --- /dev/null +++ b/native/src/subscription.rs @@ -0,0 +1,6 @@ +use crate::Event; + +pub type Subscription = iced_core::Subscription; +pub type Input = futures::channel::mpsc::Receiver; + +pub use iced_core::subscription::Connection; -- cgit From cdb7acf6c20fe13a09e75ea1c47d53ced6174698 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 10 Dec 2019 03:43:00 +0100 Subject: Implement `Subscription::map` and `from_recipe` --- native/src/subscription.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'native/src/subscription.rs') diff --git a/native/src/subscription.rs b/native/src/subscription.rs index 5fa026a2..4d000490 100644 --- a/native/src/subscription.rs +++ b/native/src/subscription.rs @@ -1,6 +1,6 @@ -use crate::Event; +use crate::{Event, Hasher}; -pub type Subscription = iced_core::Subscription; +pub type Subscription = iced_core::Subscription; pub type Input = futures::channel::mpsc::Receiver; -pub use iced_core::subscription::Connection; +pub use iced_core::subscription::Recipe; -- cgit From ba06d458d33d98bfaa5e66b3512ce7f063e8d7ba Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 14 Dec 2019 04:12:42 +0100 Subject: Move native events subscription to `iced_native` --- native/src/subscription.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'native/src/subscription.rs') diff --git a/native/src/subscription.rs b/native/src/subscription.rs index 4d000490..c25e1cb4 100644 --- a/native/src/subscription.rs +++ b/native/src/subscription.rs @@ -4,3 +4,28 @@ pub type Subscription = iced_core::Subscription; pub type Input = futures::channel::mpsc::Receiver; pub use iced_core::subscription::Recipe; + +pub fn events() -> Subscription { + Subscription::from_recipe(Events) +} + +struct Events; + +impl Recipe for Events { + type Output = Event; + + fn hash(&self, state: &mut Hasher) { + use std::hash::Hash; + + std::any::TypeId::of::().hash(state); + } + + fn stream( + self: Box, + input: Input, + ) -> futures::stream::BoxStream<'static, Self::Output> { + use futures::StreamExt; + + input.boxed() + } +} -- cgit From 293314405f5b8d4003db5ef8f428e659ae36872d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 14 Dec 2019 04:49:13 +0100 Subject: Make `iced_native` subscription input opaque --- native/src/subscription.rs | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) (limited to 'native/src/subscription.rs') diff --git a/native/src/subscription.rs b/native/src/subscription.rs index c25e1cb4..c49e24d2 100644 --- a/native/src/subscription.rs +++ b/native/src/subscription.rs @@ -1,31 +1,16 @@ use crate::{Event, Hasher}; +use futures::stream::BoxStream; -pub type Subscription = iced_core::Subscription; -pub type Input = futures::channel::mpsc::Receiver; +pub type EventStream = BoxStream<'static, Event>; -pub use iced_core::subscription::Recipe; - -pub fn events() -> Subscription { - Subscription::from_recipe(Events) -} +pub type Subscription = iced_core::Subscription; -struct Events; - -impl Recipe for Events { - type Output = Event; - - fn hash(&self, state: &mut Hasher) { - use std::hash::Hash; +pub use iced_core::subscription::Recipe; - std::any::TypeId::of::().hash(state); - } +mod events; - fn stream( - self: Box, - input: Input, - ) -> futures::stream::BoxStream<'static, Self::Output> { - use futures::StreamExt; +use events::Events; - input.boxed() - } +pub fn events() -> Subscription { + Subscription::from_recipe(Events) } -- cgit From d6c3da21f7fe7a79bcfbc2a180dc111e42300a04 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 14 Dec 2019 05:56:46 +0100 Subject: Write docs for subscriptions and reorganize a bit --- native/src/subscription.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'native/src/subscription.rs') diff --git a/native/src/subscription.rs b/native/src/subscription.rs index c49e24d2..db88867a 100644 --- a/native/src/subscription.rs +++ b/native/src/subscription.rs @@ -1,16 +1,42 @@ +//! Listen to external events in your application. use crate::{Event, Hasher}; use futures::stream::BoxStream; -pub type EventStream = BoxStream<'static, Event>; - +/// A request to listen to external events. +/// +/// Besides performing async actions on demand with [`Command`], most +/// applications also need to listen to external events passively. +/// +/// A [`Subscription`] is normally provided to some runtime, like a [`Command`], +/// and it will generate events as long as the user keeps requesting it. +/// +/// For instance, you can use a [`Subscription`] to listen to a WebSocket +/// connection, keyboard presses, mouse events, time ticks, etc. +/// +/// [`Command`]: ../struct.Command.html +/// [`Subscription`]: struct.Subscription.html pub type Subscription = iced_core::Subscription; +/// A stream of runtime events. +/// +/// It is the input of a [`Subscription`] in the native runtime. +/// +/// [`Subscription`]: type.Subscription.html +pub type EventStream = BoxStream<'static, Event>; + pub use iced_core::subscription::Recipe; mod events; use events::Events; +/// Returns a [`Subscription`] to all the runtime events. +/// +/// This subscription will notify your application of any [`Event`] handled by +/// the runtime. +/// +/// [`Subscription`]: type.Subscription.html +/// [`Event`]: ../enum.Event.html pub fn events() -> Subscription { Subscription::from_recipe(Events) } -- cgit