diff options
-rw-r--r-- | examples/stopwatch.rs | 8 | ||||
-rw-r--r-- | native/src/subscription.rs | 31 | ||||
-rw-r--r-- | native/src/subscription/events.rs | 23 | ||||
-rw-r--r-- | winit/src/application.rs | 2 |
4 files changed, 36 insertions, 28 deletions
diff --git a/examples/stopwatch.rs b/examples/stopwatch.rs index d21bdaa8..0d52a091 100644 --- a/examples/stopwatch.rs +++ b/examples/stopwatch.rs @@ -155,13 +155,13 @@ mod time { struct Every(std::time::Duration); - impl<Hasher, Input> iced_native::subscription::Recipe<Hasher, Input> for Every + impl<H, I> iced_native::subscription::Recipe<H, I> for Every where - Hasher: std::hash::Hasher, + H: std::hash::Hasher, { type Output = std::time::Instant; - fn hash(&self, state: &mut Hasher) { + fn hash(&self, state: &mut H) { use std::hash::Hash; std::any::TypeId::of::<Self>().hash(state); @@ -170,7 +170,7 @@ mod time { fn stream( self: Box<Self>, - _input: Input, + _input: I, ) -> futures::stream::BoxStream<'static, Self::Output> { use futures::stream::StreamExt; 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<T> = iced_core::Subscription<Hasher, Input, T>; -pub type Input = futures::channel::mpsc::Receiver<Event>; +pub type EventStream = BoxStream<'static, Event>; -pub use iced_core::subscription::Recipe; - -pub fn events() -> Subscription<Event> { - Subscription::from_recipe(Events) -} +pub type Subscription<T> = iced_core::Subscription<Hasher, EventStream, T>; -struct Events; - -impl Recipe<Hasher, Input> 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::<Self>().hash(state); - } +mod events; - fn stream( - self: Box<Self>, - input: Input, - ) -> futures::stream::BoxStream<'static, Self::Output> { - use futures::StreamExt; +use events::Events; - input.boxed() - } +pub fn events() -> Subscription<Event> { + Subscription::from_recipe(Events) } diff --git a/native/src/subscription/events.rs b/native/src/subscription/events.rs new file mode 100644 index 00000000..b7301828 --- /dev/null +++ b/native/src/subscription/events.rs @@ -0,0 +1,23 @@ +use crate::{ + subscription::{EventStream, Recipe}, + Event, Hasher, +}; + +pub struct Events; + +impl Recipe<Hasher, EventStream> for Events { + type Output = Event; + + fn hash(&self, state: &mut Hasher) { + use std::hash::Hash; + + std::any::TypeId::of::<Self>().hash(state); + } + + fn stream( + self: Box<Self>, + event_stream: EventStream, + ) -> futures::stream::BoxStream<'static, Self::Output> { + event_stream + } +} diff --git a/winit/src/application.rs b/winit/src/application.rs index 25396b6f..2d30e9f3 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -468,7 +468,7 @@ impl Subscriptions { let (event_sender, event_receiver) = futures::channel::mpsc::channel(100); - let stream = recipe.stream(event_receiver); + let stream = recipe.stream(event_receiver.boxed()); let proxy = proxy.clone(); let future = futures::future::select( |