Merge pull request #699 from JayceFayne/smol
Add `smol` async runtime support
This commit is contained in:
commit
2056304e39
52
CHANGELOG.md
52
CHANGELOG.md
@ -6,9 +6,54 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
### Added
|
### 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
|
## [0.1.1] - 2020-04-15
|
||||||
### Added
|
### Added
|
||||||
@ -114,7 +159,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
### Added
|
### Added
|
||||||
- First release! :tada:
|
- 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.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]: 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
|
[0.1.0-beta]: https://github.com/hecrj/iced/compare/0.1.0-alpha...0.1.0-beta
|
||||||
|
@ -41,6 +41,8 @@ tokio = ["iced_futures/tokio"]
|
|||||||
tokio_old = ["iced_futures/tokio_old"]
|
tokio_old = ["iced_futures/tokio_old"]
|
||||||
# Enables `async-std` as the `executor::Default` on native platforms
|
# Enables `async-std` as the `executor::Default` on native platforms
|
||||||
async-std = ["iced_futures/async-std"]
|
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`
|
# Enables advanced color conversion via `palette`
|
||||||
palette = ["iced_core/palette"]
|
palette = ["iced_core/palette"]
|
||||||
|
|
||||||
|
@ -6,4 +6,4 @@ edition = "2018"
|
|||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
iced = { path = "../..", features = ["tokio"] }
|
iced = { path = "../..", features = ["smol"] }
|
||||||
|
@ -36,6 +36,10 @@ version = "1.0"
|
|||||||
optional = true
|
optional = true
|
||||||
features = ["unstable"]
|
features = ["unstable"]
|
||||||
|
|
||||||
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.smol]
|
||||||
|
version = "1.2"
|
||||||
|
optional = true
|
||||||
|
|
||||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||||
wasm-bindgen-futures = "0.4"
|
wasm-bindgen-futures = "0.4"
|
||||||
|
|
||||||
|
@ -13,6 +13,9 @@ mod tokio_old;
|
|||||||
#[cfg(all(not(target_arch = "wasm32"), feature = "async-std"))]
|
#[cfg(all(not(target_arch = "wasm32"), feature = "async-std"))]
|
||||||
mod async_std;
|
mod async_std;
|
||||||
|
|
||||||
|
#[cfg(all(not(target_arch = "wasm32"), feature = "smol"))]
|
||||||
|
mod smol;
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
mod wasm_bindgen;
|
mod wasm_bindgen;
|
||||||
|
|
||||||
@ -30,6 +33,9 @@ pub use self::tokio_old::TokioOld;
|
|||||||
#[cfg(all(not(target_arch = "wasm32"), feature = "async-std"))]
|
#[cfg(all(not(target_arch = "wasm32"), feature = "async-std"))]
|
||||||
pub use self::async_std::AsyncStd;
|
pub use self::async_std::AsyncStd;
|
||||||
|
|
||||||
|
#[cfg(all(not(target_arch = "wasm32"), feature = "smol"))]
|
||||||
|
pub use self::smol::Smol;
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
pub use wasm_bindgen::WasmBindgen;
|
pub use wasm_bindgen::WasmBindgen;
|
||||||
|
|
||||||
|
18
futures/src/executor/smol.rs
Normal file
18
futures/src/executor/smol.rs
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
}
|
@ -17,10 +17,22 @@ pub mod executor;
|
|||||||
pub mod subscription;
|
pub mod subscription;
|
||||||
|
|
||||||
#[cfg(all(
|
#[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")
|
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 mod time;
|
||||||
|
|
||||||
pub use command::Command;
|
pub use command::Command;
|
||||||
|
@ -13,6 +13,41 @@ pub fn every<H: std::hash::Hasher, E>(
|
|||||||
|
|
||||||
struct Every(std::time::Duration);
|
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")]
|
#[cfg(feature = "async-std")]
|
||||||
impl<H, E> subscription::Recipe<H, E> for Every
|
impl<H, E> subscription::Recipe<H, E> for Every
|
||||||
where
|
where
|
||||||
@ -41,7 +76,7 @@ where
|
|||||||
|
|
||||||
#[cfg(all(
|
#[cfg(all(
|
||||||
any(feature = "tokio", feature = "tokio_old"),
|
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
|
impl<H, E> subscription::Recipe<H, E> for Every
|
||||||
where
|
where
|
||||||
|
@ -10,19 +10,30 @@ mod platform {
|
|||||||
#[cfg(feature = "tokio_old")]
|
#[cfg(feature = "tokio_old")]
|
||||||
type Executor = executor::TokioOld;
|
type Executor = executor::TokioOld;
|
||||||
|
|
||||||
#[cfg(all(not(feature = "tokio_old"), feature = "tokio"))]
|
#[cfg(all(feature = "tokio", not(feature = "tokio_old")))]
|
||||||
type Executor = executor::Tokio;
|
type Executor = executor::Tokio;
|
||||||
|
|
||||||
#[cfg(all(
|
#[cfg(all(
|
||||||
|
feature = "async-std",
|
||||||
not(any(feature = "tokio_old", feature = "tokio")),
|
not(any(feature = "tokio_old", feature = "tokio")),
|
||||||
feature = "async-std"
|
|
||||||
))]
|
))]
|
||||||
type Executor = executor::AsyncStd;
|
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(
|
#[cfg(not(any(
|
||||||
feature = "tokio_old",
|
feature = "tokio_old",
|
||||||
feature = "tokio",
|
feature = "tokio",
|
||||||
feature = "async-std"
|
feature = "async-std",
|
||||||
|
feature = "smol",
|
||||||
)))]
|
)))]
|
||||||
type Executor = executor::ThreadPool;
|
type Executor = executor::ThreadPool;
|
||||||
|
|
||||||
|
@ -191,7 +191,12 @@ pub mod widget;
|
|||||||
pub mod window;
|
pub mod window;
|
||||||
|
|
||||||
#[cfg(all(
|
#[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")
|
not(target_arch = "wasm32")
|
||||||
))]
|
))]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
@ -200,6 +205,7 @@ pub mod window;
|
|||||||
feature = "tokio",
|
feature = "tokio",
|
||||||
feature = "tokio_old",
|
feature = "tokio_old",
|
||||||
feature = "async-std"
|
feature = "async-std"
|
||||||
|
feature = "smol"
|
||||||
)))
|
)))
|
||||||
)]
|
)]
|
||||||
pub mod time;
|
pub mod time;
|
||||||
|
Loading…
Reference in New Issue
Block a user