summaryrefslogtreecommitdiffstats
path: root/native/src/subscription.rs
blob: c25e1cb4ace0690e74f49a6462cf1fdfb6a3d3cc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use crate::{Event, Hasher};

pub type Subscription<T> = iced_core::Subscription<Hasher, Input, T>;
pub type Input = futures::channel::mpsc::Receiver<Event>;

pub use iced_core::subscription::Recipe;

pub fn events() -> Subscription<Event> {
    Subscription::from_recipe(Events)
}

struct Events;

impl Recipe<Hasher, Input> 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>,
        input: Input,
    ) -> futures::stream::BoxStream<'static, Self::Output> {
        use futures::StreamExt;

        input.boxed()
    }
}