summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2021-01-15 19:04:23 +0100
committerLibravatar GitHub <noreply@github.com>2021-01-15 19:04:23 +0100
commit2056304e39c32ef5613eb6e82036586043002c08 (patch)
treed6f780a018222ed4a4476cfbc634543c7499b462
parent984583b0cca86d7ba8f865489cbebeb181349c19 (diff)
parentfd2c96c8e36eb37ea4a53aafe0986b569a4e3753 (diff)
downloadiced-2056304e39c32ef5613eb6e82036586043002c08.tar.gz
iced-2056304e39c32ef5613eb6e82036586043002c08.tar.bz2
iced-2056304e39c32ef5613eb6e82036586043002c08.zip
Merge pull request #699 from JayceFayne/smol
Add `smol` async runtime support
-rw-r--r--CHANGELOG.md52
-rw-r--r--Cargo.toml2
-rw-r--r--examples/stopwatch/Cargo.toml2
-rw-r--r--futures/Cargo.toml4
-rw-r--r--futures/src/executor.rs6
-rw-r--r--futures/src/executor/smol.rs18
-rw-r--r--futures/src/lib.rs16
-rw-r--r--futures/src/time.rs37
-rw-r--r--src/executor.rs17
-rw-r--r--src/lib.rs8
10 files changed, 151 insertions, 11 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ee650337..70673f79 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,9 +6,54 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
-- `"system_font"` feature gates reading system fonts. [#370]
+- Support for the [`smol`] async runtime. [#699]
+
+[#699]: https://github.com/hecrj/iced/pull/699
+[`smol`]: https://github.com/smol-rs/smol
+
+## [0.2.0] - 2020-11-26
+- __[`Canvas` interactivity][canvas]__ (#325)
+ A trait-based approach to react to mouse and keyboard interactions in [the `Canvas` widget][#193].
+
+- __[`iced_graphics` subcrate][opengl]__ (#354)
+ A backend-agnostic graphics subcrate that can be leveraged to build new renderers.
+
+- __[OpenGL renderer][opengl]__ (#354)
+ An OpenGL renderer powered by [`iced_graphics`], [`glow`], and [`glutin`]. It is an alternative to the default [`wgpu`] renderer.
+
+- __[Overlay support][pick_list]__ (#444)
+ Basic support for superpositioning interactive widgets on top of other widgets.
+
+- __[Faster event loop][view]__ (#597)
+ The event loop now takes advantage of the data dependencies in [The Elm Architecture] and leverages the borrow checker to keep the widget tree alive between iterations, avoiding unnecessary rebuilds.
+
+- __[Event capturing][event]__ (#614)
+ The runtime now can tell whether a widget has handled an event or not, easing [integration with existing applications].
+
+- __[`PickList` widget][pick_list]__ (#444)
+ A drop-down selector widget built on top of the new overlay support.
+
+- __[`QRCode` widget][qr_code]__ (#622)
+ A widget that displays a QR code, powered by [the `qrcode` crate].
+
+[canvas]: https://github.com/hecrj/iced/pull/325
+[opengl]: https://github.com/hecrj/iced/pull/354
+[`iced_graphics`]: https://github.com/hecrj/iced/pull/354
+[pane_grid]: https://github.com/hecrj/iced/pull/397
+[pick_list]: https://github.com/hecrj/iced/pull/444
+[error]: https://github.com/hecrj/iced/pull/514
+[view]: https://github.com/hecrj/iced/pull/597
+[event]: https://github.com/hecrj/iced/pull/614
+[color]: https://github.com/hecrj/iced/pull/200
+[qr_code]: https://github.com/hecrj/iced/pull/622
+[#193]: https://github.com/hecrj/iced/pull/193
+[`glutin`]: https://github.com/rust-windowing/glutin
+[`wgpu`]: https://github.com/gfx-rs/wgpu-rs
+[`glow`]: https://github.com/grovesNL/glow
+[the `qrcode` crate]: https://docs.rs/qrcode/0.12.0/qrcode/
+[integration with existing applications]: https://github.com/hecrj/iced/pull/183
+[The Elm Architecture]: https://guide.elm-lang.org/architecture/
-[#370]: https://github.com/hecrj/iced/pull/370
## [0.1.1] - 2020-04-15
### Added
@@ -114,7 +159,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- First release! :tada:
-[Unreleased]: https://github.com/hecrj/iced/compare/0.1.1...HEAD
+[Unreleased]: https://github.com/hecrj/iced/compare/0.2.0...HEAD
+[0.2.0]: https://github.com/hecrj/iced/compare/0.1.1...0.2.0
[0.1.1]: https://github.com/hecrj/iced/compare/0.1.0...0.1.1
[0.1.0]: https://github.com/hecrj/iced/compare/0.1.0-beta...0.1.0
[0.1.0-beta]: https://github.com/hecrj/iced/compare/0.1.0-alpha...0.1.0-beta
diff --git a/Cargo.toml b/Cargo.toml
index 6221ae4b..75499df9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -41,6 +41,8 @@ tokio = ["iced_futures/tokio"]
tokio_old = ["iced_futures/tokio_old"]
# Enables `async-std` as the `executor::Default` on native platforms
async-std = ["iced_futures/async-std"]
+# Enables `smol` as the `executor::Default` on native platforms
+smol = ["iced_futures/smol"]
# Enables advanced color conversion via `palette`
palette = ["iced_core/palette"]
diff --git a/examples/stopwatch/Cargo.toml b/examples/stopwatch/Cargo.toml
index 075aa111..9f935951 100644
--- a/examples/stopwatch/Cargo.toml
+++ b/examples/stopwatch/Cargo.toml
@@ -6,4 +6,4 @@ edition = "2018"
publish = false
[dependencies]
-iced = { path = "../..", features = ["tokio"] }
+iced = { path = "../..", features = ["smol"] }
diff --git a/futures/Cargo.toml b/futures/Cargo.toml
index 92b504a6..c266f705 100644
--- a/futures/Cargo.toml
+++ b/futures/Cargo.toml
@@ -36,6 +36,10 @@ version = "1.0"
optional = true
features = ["unstable"]
+[target.'cfg(not(target_arch = "wasm32"))'.dependencies.smol]
+version = "1.2"
+optional = true
+
[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen-futures = "0.4"
diff --git a/futures/src/executor.rs b/futures/src/executor.rs
index fa87216a..b35b5bc1 100644
--- a/futures/src/executor.rs
+++ b/futures/src/executor.rs
@@ -13,6 +13,9 @@ mod tokio_old;
#[cfg(all(not(target_arch = "wasm32"), feature = "async-std"))]
mod async_std;
+#[cfg(all(not(target_arch = "wasm32"), feature = "smol"))]
+mod smol;
+
#[cfg(target_arch = "wasm32")]
mod wasm_bindgen;
@@ -30,6 +33,9 @@ pub use self::tokio_old::TokioOld;
#[cfg(all(not(target_arch = "wasm32"), feature = "async-std"))]
pub use self::async_std::AsyncStd;
+#[cfg(all(not(target_arch = "wasm32"), feature = "smol"))]
+pub use self::smol::Smol;
+
#[cfg(target_arch = "wasm32")]
pub use wasm_bindgen::WasmBindgen;
diff --git a/futures/src/executor/smol.rs b/futures/src/executor/smol.rs
new file mode 100644
index 00000000..deafd43a
--- /dev/null
+++ b/futures/src/executor/smol.rs
@@ -0,0 +1,18 @@
+use crate::Executor;
+
+use futures::Future;
+
+/// A `smol` runtime.
+#[cfg_attr(docsrs, doc(cfg(feature = "smol")))]
+#[derive(Debug)]
+pub struct Smol;
+
+impl Executor for Smol {
+ fn new() -> Result<Self, futures::io::Error> {
+ Ok(Self)
+ }
+
+ fn spawn(&self, future: impl Future<Output = ()> + Send + 'static) {
+ smol::spawn(future).detach();
+ }
+}
diff --git a/futures/src/lib.rs b/futures/src/lib.rs
index c7c6fd3a..01cf5c89 100644
--- a/futures/src/lib.rs
+++ b/futures/src/lib.rs
@@ -17,10 +17,22 @@ pub mod executor;
pub mod subscription;
#[cfg(all(
- any(feature = "tokio", feature = "tokio_old", feature = "async-std"),
+ any(
+ feature = "tokio",
+ feature = "tokio_old",
+ feature = "async-std",
+ feature = "smol"
+ ),
not(target_arch = "wasm32")
))]
-#[cfg_attr(docsrs, doc(cfg(any(feature = "tokio", feature = "async-std"))))]
+#[cfg_attr(
+ docsrs,
+ doc(cfg(any(
+ feature = "tokio",
+ feature = "async-std",
+ feature = "smol"
+ )))
+)]
pub mod time;
pub use command::Command;
diff --git a/futures/src/time.rs b/futures/src/time.rs
index d015d2f0..c11942d2 100644
--- a/futures/src/time.rs
+++ b/futures/src/time.rs
@@ -13,6 +13,41 @@ pub fn every<H: std::hash::Hasher, E>(
struct Every(std::time::Duration);
+#[cfg(all(
+ not(any(feature = "tokio_old", feature = "tokio", feature = "async-std")),
+ feature = "smol"
+))]
+impl<H, E> subscription::Recipe<H, E> 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::<Self>().hash(state);
+ self.0.hash(state);
+ }
+
+ fn stream(
+ self: Box<Self>,
+ _input: futures::stream::BoxStream<'static, E>,
+ ) -> futures::stream::BoxStream<'static, Self::Output> {
+ use futures::stream::StreamExt;
+ use std::time::Instant;
+
+ let duration = self.0;
+
+ futures::stream::unfold(Instant::now(), move |last_tick| async move {
+ let last_tick = smol::Timer::at(last_tick + duration).await;
+
+ Some((last_tick, last_tick))
+ })
+ .boxed()
+ }
+}
+
#[cfg(feature = "async-std")]
impl<H, E> subscription::Recipe<H, E> for Every
where
@@ -41,7 +76,7 @@ where
#[cfg(all(
any(feature = "tokio", feature = "tokio_old"),
- not(feature = "async-std")
+ not(any(feature = "async-std", feature = "smol"))
))]
impl<H, E> subscription::Recipe<H, E> for Every
where
diff --git a/src/executor.rs b/src/executor.rs
index 0333bc1d..9f3656b1 100644
--- a/src/executor.rs
+++ b/src/executor.rs
@@ -10,19 +10,30 @@ mod platform {
#[cfg(feature = "tokio_old")]
type Executor = executor::TokioOld;
- #[cfg(all(not(feature = "tokio_old"), feature = "tokio"))]
+ #[cfg(all(feature = "tokio", not(feature = "tokio_old")))]
type Executor = executor::Tokio;
#[cfg(all(
+ feature = "async-std",
not(any(feature = "tokio_old", feature = "tokio")),
- feature = "async-std"
))]
type Executor = executor::AsyncStd;
+ #[cfg(all(
+ feature = "smol",
+ not(any(
+ feature = "tokio_old",
+ feature = "tokio",
+ feature = "async-std"
+ )),
+ ))]
+ type Executor = executor::Smol;
+
#[cfg(not(any(
feature = "tokio_old",
feature = "tokio",
- feature = "async-std"
+ feature = "async-std",
+ feature = "smol",
)))]
type Executor = executor::ThreadPool;
diff --git a/src/lib.rs b/src/lib.rs
index 3578ea82..dedcac7a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -191,7 +191,12 @@ pub mod widget;
pub mod window;
#[cfg(all(
- any(feature = "tokio", feature = "tokio_old", feature = "async-std"),
+ any(
+ feature = "tokio",
+ feature = "tokio_old",
+ feature = "async-std",
+ feature = "smol"
+ ),
not(target_arch = "wasm32")
))]
#[cfg_attr(
@@ -200,6 +205,7 @@ pub mod window;
feature = "tokio",
feature = "tokio_old",
feature = "async-std"
+ feature = "smol"
)))
)]
pub mod time;