diff options
author | 2020-04-30 05:37:44 +0200 | |
---|---|---|
committer | 2020-04-30 05:37:44 +0200 | |
commit | e2076612cb98d04a8a48add14d0068c2974d5653 (patch) | |
tree | 83ee2bcd2a0ef675a1eb0a7bc9313884055aee67 /examples/solar_system | |
parent | bb9ccc4f62ceea08dc1ef0c6c4d3d219897e44a1 (diff) | |
download | iced-e2076612cb98d04a8a48add14d0068c2974d5653.tar.gz iced-e2076612cb98d04a8a48add14d0068c2974d5653.tar.bz2 iced-e2076612cb98d04a8a48add14d0068c2974d5653.zip |
Implement `time::every` in `iced_futures`
Diffstat (limited to 'examples/solar_system')
-rw-r--r-- | examples/solar_system/Cargo.toml | 4 | ||||
-rw-r--r-- | examples/solar_system/src/main.rs | 40 |
2 files changed, 3 insertions, 41 deletions
diff --git a/examples/solar_system/Cargo.toml b/examples/solar_system/Cargo.toml index 0555aa96..44ced729 100644 --- a/examples/solar_system/Cargo.toml +++ b/examples/solar_system/Cargo.toml @@ -6,7 +6,5 @@ edition = "2018" publish = false [dependencies] -iced = { path = "../..", features = ["canvas", "async-std", "debug"] } -iced_native = { path = "../../native" } -async-std = { version = "1.0", features = ["unstable"] } +iced = { path = "../..", features = ["canvas", "tokio", "debug"] } rand = "0.7" diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index a25e43df..98bd3b21 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -8,8 +8,8 @@ //! [1]: https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Basic_animations#An_animated_solar_system use iced::{ canvas::{self, Cursor, Path, Stroke}, - executor, window, Application, Canvas, Color, Command, Element, Length, - Point, Rectangle, Settings, Size, Subscription, Vector, + executor, time, window, Application, Canvas, Color, Command, Element, + Length, Point, Rectangle, Settings, Size, Subscription, Vector, }; use std::time::Instant; @@ -212,39 +212,3 @@ impl<Message> canvas::Program<Message> for State { vec![background, system] } } - -mod time { - use iced::futures; - use std::time::Instant; - - pub fn every(duration: std::time::Duration) -> iced::Subscription<Instant> { - iced::Subscription::from_recipe(Every(duration)) - } - - struct Every(std::time::Duration); - - impl<H, I> iced_native::subscription::Recipe<H, I> for Every - where - H: std::hash::Hasher, - { - type Output = Instant; - - fn hash(&self, state: &mut H) { - use std::hash::Hash; - - std::any::TypeId::of::<Self>().hash(state); - self.0.hash(state); - } - - fn stream( - self: Box<Self>, - _input: futures::stream::BoxStream<'static, I>, - ) -> futures::stream::BoxStream<'static, Self::Output> { - use futures::stream::StreamExt; - - async_std::stream::interval(self.0) - .map(|_| Instant::now()) - .boxed() - } - } -} |