summaryrefslogtreecommitdiffstats
path: root/native/src/subscription/events.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--native/src/subscription/events.rs19
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()
}
}