diff options
author | 2019-12-14 04:12:42 +0100 | |
---|---|---|
committer | 2019-12-14 04:12:42 +0100 | |
commit | ba06d458d33d98bfaa5e66b3512ce7f063e8d7ba (patch) | |
tree | 52e9ea551c2c63943fab3ebd7e24263480b5bbce /native | |
parent | e71978456a0af40a1004a5c5ce1c7cdc8b709ac0 (diff) | |
download | iced-ba06d458d33d98bfaa5e66b3512ce7f063e8d7ba.tar.gz iced-ba06d458d33d98bfaa5e66b3512ce7f063e8d7ba.tar.bz2 iced-ba06d458d33d98bfaa5e66b3512ce7f063e8d7ba.zip |
Move native events subscription to `iced_native`
Diffstat (limited to 'native')
-rw-r--r-- | native/src/subscription.rs | 25 |
1 files changed, 25 insertions, 0 deletions
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<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() + } +} |