Allow switching executor::Default
with features
This commit is contained in:
parent
e8316b2087
commit
ad500441af
11
Cargo.toml
11
Cargo.toml
@ -12,12 +12,16 @@ keywords = ["gui", "ui", "graphics", "interface", "widgets"]
|
|||||||
categories = ["gui"]
|
categories = ["gui"]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
# Enables the Image widget
|
# Enables the `Image` widget
|
||||||
image = ["iced_wgpu/image"]
|
image = ["iced_wgpu/image"]
|
||||||
# Enables the Svg widget
|
# Enables the `Svg` widget
|
||||||
svg = ["iced_wgpu/svg"]
|
svg = ["iced_wgpu/svg"]
|
||||||
# Enables a debug view in native platforms (press F12)
|
# Enables a debug view in native platforms (press F12)
|
||||||
debug = ["iced_winit/debug"]
|
debug = ["iced_winit/debug"]
|
||||||
|
# Enables `tokio` as the `executor::Default` on native platforms
|
||||||
|
tokio = ["iced_futures/tokio"]
|
||||||
|
# Enables `async-std` as the `executor::Default` on native platforms
|
||||||
|
async-std = ["iced_futures/async-std"]
|
||||||
|
|
||||||
[badges]
|
[badges]
|
||||||
maintenance = { status = "actively-developed" }
|
maintenance = { status = "actively-developed" }
|
||||||
@ -45,6 +49,9 @@ members = [
|
|||||||
"examples/tour",
|
"examples/tour",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
iced_futures = { version = "0.1.0-alpha", path = "futures" }
|
||||||
|
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
iced_winit = { version = "0.1.0-alpha", path = "winit" }
|
iced_winit = { version = "0.1.0-alpha", path = "winit" }
|
||||||
iced_wgpu = { version = "0.1.0", path = "wgpu" }
|
iced_wgpu = { version = "0.1.0", path = "wgpu" }
|
||||||
|
@ -6,8 +6,7 @@ edition = "2018"
|
|||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
iced = { path = "../..", features = ["image", "debug"] }
|
iced = { path = "../..", features = ["image", "debug", "tokio"] }
|
||||||
iced_futures = { path = "../../futures", features = ["tokio"] }
|
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
rand = { version = "0.7", features = ["wasm-bindgen"] }
|
rand = { version = "0.7", features = ["wasm-bindgen"] }
|
||||||
|
@ -27,12 +27,7 @@ enum Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Application for Pokedex {
|
impl Application for Pokedex {
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
type Executor = iced::executor::Default;
|
||||||
type Executor = iced_futures::executor::Tokio;
|
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
type Executor = iced_futures::executor::WasmBindgen;
|
|
||||||
|
|
||||||
type Message = Message;
|
type Message = Message;
|
||||||
|
|
||||||
fn new() -> (Pokedex, Command<Message>) {
|
fn new() -> (Pokedex, Command<Message>) {
|
||||||
|
@ -6,8 +6,7 @@ edition = "2018"
|
|||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
iced = { path = "../.." }
|
iced = { path = "../..", features = ["async-std"] }
|
||||||
iced_futures = { path = "../../futures", features = ["async-std"] }
|
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
|
||||||
|
@ -38,12 +38,7 @@ enum Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Application for Todos {
|
impl Application for Todos {
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
type Executor = iced::executor::Default;
|
||||||
type Executor = iced_futures::executor::AsyncStd;
|
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
type Executor = iced_futures::executor::WasmBindgen;
|
|
||||||
|
|
||||||
type Message = Message;
|
type Message = Message;
|
||||||
|
|
||||||
fn new() -> (Todos, Command<Message>) {
|
fn new() -> (Todos, Command<Message>) {
|
||||||
|
@ -5,38 +5,49 @@ pub use platform::Default;
|
|||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
mod platform {
|
mod platform {
|
||||||
use iced_winit::{executor::ThreadPool, futures, Executor};
|
use iced_futures::{executor, futures};
|
||||||
|
|
||||||
|
#[cfg(feature = "tokio")]
|
||||||
|
type Executor = executor::Tokio;
|
||||||
|
|
||||||
|
#[cfg(all(not(feature = "tokio"), feature = "async-std"))]
|
||||||
|
type Executor = executor::AsyncStd;
|
||||||
|
|
||||||
|
#[cfg(not(any(feature = "tokio", feature = "async-std")))]
|
||||||
|
type Executor = executor::ThreadPool;
|
||||||
|
|
||||||
/// A default cross-platform executor.
|
/// A default cross-platform executor.
|
||||||
///
|
///
|
||||||
/// - On native platforms, it will use a
|
/// - On native platforms, it will use:
|
||||||
/// `iced_futures::executor::ThreadPool`.
|
/// - `iced_futures::executor::Tokio` when the `tokio` feature is enabled.
|
||||||
|
/// - `iced_futures::executor::AsyncStd` when the `async-std` feature is
|
||||||
|
/// enabled.
|
||||||
|
/// - `iced_futures::executor::ThreadPool` otherwise.
|
||||||
/// - On the Web, it will use `iced_futures::executor::WasmBindgen`.
|
/// - On the Web, it will use `iced_futures::executor::WasmBindgen`.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Default(ThreadPool);
|
pub struct Default(Executor);
|
||||||
|
|
||||||
impl Executor for Default {
|
impl super::Executor for Default {
|
||||||
fn new() -> Result<Self, futures::io::Error> {
|
fn new() -> Result<Self, futures::io::Error> {
|
||||||
Ok(Default(ThreadPool::new()?))
|
Ok(Default(Executor::new()?))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn spawn(
|
fn spawn(
|
||||||
&self,
|
&self,
|
||||||
future: impl futures::Future<Output = ()> + Send + 'static,
|
future: impl futures::Future<Output = ()> + Send + 'static,
|
||||||
) {
|
) {
|
||||||
self.0.spawn(future);
|
let _ = self.0.spawn(future);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
mod platform {
|
mod platform {
|
||||||
use iced_web::{executor::WasmBindgen, futures, Executor};
|
use iced_futures::{executor::WasmBindgen, futures, Executor};
|
||||||
|
|
||||||
/// A default cross-platform executor.
|
/// A default cross-platform executor.
|
||||||
///
|
///
|
||||||
/// - On native platforms, it will use a
|
/// - On native platforms, it will use `iced_futures::executor::ThreadPool`.
|
||||||
/// `iced_futures::executor::ThreadPool`.
|
|
||||||
/// - On the Web, it will use `iced_futures::executor::WasmBindgen`.
|
/// - On the Web, it will use `iced_futures::executor::WasmBindgen`.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Default(WasmBindgen);
|
pub struct Default(WasmBindgen);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user