diff options
author | 2020-11-10 22:57:19 +0100 | |
---|---|---|
committer | 2020-11-10 22:57:19 +0100 | |
commit | 2f5a3dacd933a52931a1bb169138d52402413956 (patch) | |
tree | 65995b4304543ea6a6400af3c8e11eae630dd22b /native/src/subscription | |
parent | d0402d072d3f4e128c55fc0a6184c5f7c712bb20 (diff) | |
parent | 86fa12229e7117306b8297a09aa22c99802600c8 (diff) | |
download | iced-2f5a3dacd933a52931a1bb169138d52402413956.tar.gz iced-2f5a3dacd933a52931a1bb169138d52402413956.tar.bz2 iced-2f5a3dacd933a52931a1bb169138d52402413956.zip |
Merge pull request #608 from hecrj/remove-pane-grid-focus
Improve flexibility of `PaneGrid`
Diffstat (limited to 'native/src/subscription')
-rw-r--r-- | native/src/subscription/events.rs | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/native/src/subscription/events.rs b/native/src/subscription/events.rs index ceae467d..a1ae6051 100644 --- a/native/src/subscription/events.rs +++ b/native/src/subscription/events.rs @@ -2,17 +2,26 @@ use crate::{ subscription::{EventStream, Recipe}, Event, Hasher, }; +use iced_futures::futures::future; +use iced_futures::futures::StreamExt; use iced_futures::BoxStream; -pub struct Events; +pub struct Events<Message> { + pub(super) f: fn(Event) -> Option<Message>, +} -impl Recipe<Hasher, Event> for Events { - type Output = Event; +impl<Message> Recipe<Hasher, Event> for Events<Message> +where + Message: 'static + Send, +{ + type Output = Message; fn hash(&self, state: &mut Hasher) { use std::hash::Hash; - std::any::TypeId::of::<Self>().hash(state); + struct Marker; + std::any::TypeId::of::<Marker>().hash(state); + self.f.hash(state); } fn stream( @@ -20,5 +29,7 @@ impl Recipe<Hasher, Event> for Events { event_stream: EventStream, ) -> BoxStream<Self::Output> { event_stream + .filter_map(move |event| future::ready((self.f)(event))) + .boxed() } } |