From e2076612cb98d04a8a48add14d0068c2974d5653 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 30 Apr 2020 05:37:44 +0200 Subject: Implement `time::every` in `iced_futures` --- examples/game_of_life/Cargo.toml | 4 +--- examples/game_of_life/src/main.rs | 3 +-- examples/game_of_life/src/time.rs | 34 ---------------------------------- 3 files changed, 2 insertions(+), 39 deletions(-) delete mode 100644 examples/game_of_life/src/time.rs (limited to 'examples/game_of_life') diff --git a/examples/game_of_life/Cargo.toml b/examples/game_of_life/Cargo.toml index 8855b3e8..413493ae 100644 --- a/examples/game_of_life/Cargo.toml +++ b/examples/game_of_life/Cargo.toml @@ -6,7 +6,5 @@ edition = "2018" publish = false [dependencies] -iced = { path = "../..", features = ["async-std", "canvas", "debug"] } -iced_native = { path = "../../native" } -async-std = { version = "1.0", features = ["unstable"] } +iced = { path = "../..", features = ["canvas", "tokio"] } itertools = "0.9" diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs index 9fb4c3e7..5a58a8cb 100644 --- a/examples/game_of_life/src/main.rs +++ b/examples/game_of_life/src/main.rs @@ -1,14 +1,13 @@ //! This example showcases an interactive version of the Game of Life, invented //! by John Conway. It leverages a `Canvas` together with other widgets. mod style; -mod time; use grid::Grid; use iced::{ button::{self, Button}, executor, slider::{self, Slider}, - Align, Application, Column, Command, Container, Element, Length, Row, + time, Align, Application, Column, Command, Container, Element, Length, Row, Settings, Subscription, Text, }; use std::time::{Duration, Instant}; diff --git a/examples/game_of_life/src/time.rs b/examples/game_of_life/src/time.rs deleted file mode 100644 index 7b475ecd..00000000 --- a/examples/game_of_life/src/time.rs +++ /dev/null @@ -1,34 +0,0 @@ -use iced::futures; - -pub fn every( - duration: std::time::Duration, -) -> iced::Subscription { - iced::Subscription::from_recipe(Every(duration)) -} - -struct Every(std::time::Duration); - -impl iced_native::subscription::Recipe for Every -where - H: std::hash::Hasher, -{ - type Output = std::time::Instant; - - fn hash(&self, state: &mut H) { - use std::hash::Hash; - - std::any::TypeId::of::().hash(state); - self.0.hash(state); - } - - fn stream( - self: Box, - _input: futures::stream::BoxStream<'static, I>, - ) -> futures::stream::BoxStream<'static, Self::Output> { - use futures::stream::StreamExt; - - async_std::stream::interval(self.0) - .map(|_| std::time::Instant::now()) - .boxed() - } -} -- cgit