Remove async-std support (RIP)
This commit is contained in:
parent
57cb14ce38
commit
91996372cb
8 changed files with 13 additions and 104 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
|
@ -378,7 +378,6 @@ dependencies = [
|
|||
"async-global-executor",
|
||||
"async-io",
|
||||
"async-lock",
|
||||
"async-process",
|
||||
"crossbeam-utils",
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
|
|
@ -2434,7 +2433,6 @@ dependencies = [
|
|||
name = "iced_futures"
|
||||
version = "0.14.0-dev"
|
||||
dependencies = [
|
||||
"async-std",
|
||||
"futures",
|
||||
"iced_core",
|
||||
"log",
|
||||
|
|
@ -5744,12 +5742,12 @@ dependencies = [
|
|||
name = "todos"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"async-std",
|
||||
"directories",
|
||||
"iced",
|
||||
"iced_test",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
"tracing-subscriber",
|
||||
"uuid",
|
||||
"wasmtimer",
|
||||
|
|
|
|||
|
|
@ -47,8 +47,6 @@ debug = ["iced_winit/debug"]
|
|||
thread-pool = ["iced_futures/thread-pool"]
|
||||
# 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"]
|
||||
# Enables `smol` as the `executor::Default` on native platforms
|
||||
smol = ["iced_futures/smol"]
|
||||
# Enables querying system information
|
||||
|
|
@ -146,7 +144,6 @@ iced_wgpu = { version = "0.14.0-dev", path = "wgpu" }
|
|||
iced_widget = { version = "0.14.0-dev", path = "widget" }
|
||||
iced_winit = { version = "0.14.0-dev", path = "winit" }
|
||||
|
||||
async-std = "1.0"
|
||||
bitflags = "2.0"
|
||||
bytemuck = { version = "1.0", features = ["derive"] }
|
||||
bytes = "1.6"
|
||||
|
|
|
|||
|
|
@ -7,14 +7,14 @@ publish = false
|
|||
|
||||
[dependencies]
|
||||
iced.workspace = true
|
||||
iced.features = ["async-std", "debug"]
|
||||
iced.features = ["tokio", "debug"]
|
||||
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
uuid = { version = "1.0", features = ["v4", "fast-rng", "serde"] }
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
async-std.workspace = true
|
||||
tokio.workspace = true
|
||||
directories = "6.0"
|
||||
tracing-subscriber = "0.3"
|
||||
|
||||
|
|
|
|||
|
|
@ -482,7 +482,6 @@ enum LoadError {
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
enum SaveError {
|
||||
File,
|
||||
Write,
|
||||
Format,
|
||||
}
|
||||
|
|
@ -504,15 +503,7 @@ impl SavedState {
|
|||
}
|
||||
|
||||
async fn load() -> Result<SavedState, LoadError> {
|
||||
use async_std::prelude::*;
|
||||
|
||||
let mut contents = String::new();
|
||||
|
||||
let mut file = async_std::fs::File::open(Self::path())
|
||||
.await
|
||||
.map_err(|_| LoadError::File)?;
|
||||
|
||||
file.read_to_string(&mut contents)
|
||||
let contents = tokio::fs::read_to_string(Self::path())
|
||||
.await
|
||||
.map_err(|_| LoadError::File)?;
|
||||
|
||||
|
|
@ -520,31 +511,25 @@ impl SavedState {
|
|||
}
|
||||
|
||||
async fn save(self) -> Result<(), SaveError> {
|
||||
use async_std::prelude::*;
|
||||
|
||||
let json = serde_json::to_string_pretty(&self)
|
||||
.map_err(|_| SaveError::Format)?;
|
||||
|
||||
let path = Self::path();
|
||||
|
||||
if let Some(dir) = path.parent() {
|
||||
async_std::fs::create_dir_all(dir)
|
||||
tokio::fs::create_dir_all(dir)
|
||||
.await
|
||||
.map_err(|_| SaveError::File)?;
|
||||
.map_err(|_| SaveError::Write)?;
|
||||
}
|
||||
|
||||
{
|
||||
let mut file = async_std::fs::File::create(path)
|
||||
.await
|
||||
.map_err(|_| SaveError::File)?;
|
||||
|
||||
file.write_all(json.as_bytes())
|
||||
tokio::fs::write(path, json.as_bytes())
|
||||
.await
|
||||
.map_err(|_| SaveError::Write)?;
|
||||
}
|
||||
|
||||
// This is a simple way to save at most once every couple seconds
|
||||
async_std::task::sleep(std::time::Duration::from_secs(2)).await;
|
||||
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -570,7 +555,7 @@ impl SavedState {
|
|||
}
|
||||
|
||||
async fn save(self) -> Result<(), SaveError> {
|
||||
let storage = Self::storage().ok_or(SaveError::File)?;
|
||||
let storage = Self::storage().ok_or(SaveError::Write)?;
|
||||
|
||||
let json = serde_json::to_string_pretty(&self)
|
||||
.map_err(|_| SaveError::Format)?;
|
||||
|
|
|
|||
|
|
@ -30,10 +30,6 @@ log.workspace = true
|
|||
rustc-hash.workspace = true
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
async-std.workspace = true
|
||||
async-std.optional = true
|
||||
async-std.features = ["unstable"]
|
||||
|
||||
smol.workspace = true
|
||||
smol.optional = true
|
||||
|
||||
|
|
|
|||
|
|
@ -2,10 +2,9 @@
|
|||
//!
|
||||
//! - On native platforms, it will use:
|
||||
//! - `backend::native::tokio` when the `tokio` feature is enabled.
|
||||
//! - `backend::native::async-std` when the `async-std` feature is
|
||||
//! enabled.
|
||||
//! - `backend::native::smol` when the `smol` feature is enabled.
|
||||
//! - `backend::native::thread_pool` otherwise.
|
||||
//! - `backend::native::thread_pool` when the `thread-pool` feature is enabled.
|
||||
//! - `backend::null` otherwise.
|
||||
//!
|
||||
//! - On Wasm, it will use `backend::wasm::wasm_bindgen`.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
|
|
@ -13,24 +12,17 @@ mod platform {
|
|||
#[cfg(feature = "tokio")]
|
||||
pub use crate::backend::native::tokio::*;
|
||||
|
||||
#[cfg(all(feature = "async-std", not(feature = "tokio"),))]
|
||||
pub use crate::backend::native::async_std::*;
|
||||
|
||||
#[cfg(all(
|
||||
feature = "smol",
|
||||
not(any(feature = "tokio", feature = "async-std")),
|
||||
))]
|
||||
#[cfg(all(feature = "smol", not(feature = "tokio"),))]
|
||||
pub use crate::backend::native::smol::*;
|
||||
|
||||
#[cfg(all(
|
||||
feature = "thread-pool",
|
||||
not(any(feature = "tokio", feature = "async-std", feature = "smol"))
|
||||
not(any(feature = "tokio", feature = "smol"))
|
||||
))]
|
||||
pub use crate::backend::native::thread_pool::*;
|
||||
|
||||
#[cfg(not(any(
|
||||
feature = "tokio",
|
||||
feature = "async-std",
|
||||
feature = "smol",
|
||||
feature = "thread-pool"
|
||||
)))]
|
||||
|
|
|
|||
|
|
@ -2,9 +2,6 @@
|
|||
#[cfg(feature = "tokio")]
|
||||
pub mod tokio;
|
||||
|
||||
#[cfg(feature = "async-std")]
|
||||
pub mod async_std;
|
||||
|
||||
#[cfg(feature = "smol")]
|
||||
pub mod smol;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,56 +0,0 @@
|
|||
//! An `async-std` backend.
|
||||
|
||||
/// An `async-std` executor.
|
||||
#[derive(Debug)]
|
||||
pub struct Executor;
|
||||
|
||||
impl crate::Executor for Executor {
|
||||
fn new() -> Result<Self, futures::io::Error> {
|
||||
Ok(Self)
|
||||
}
|
||||
|
||||
#[allow(clippy::let_underscore_future)]
|
||||
fn spawn(&self, future: impl Future<Output = ()> + Send + 'static) {
|
||||
let _ = async_std::task::spawn(future);
|
||||
}
|
||||
}
|
||||
|
||||
pub mod time {
|
||||
//! Listen and react to time.
|
||||
use crate::subscription::{self, Hasher, Subscription};
|
||||
|
||||
/// Returns a [`Subscription`] that produces messages at a set interval.
|
||||
///
|
||||
/// The first message is produced after a `duration`, and then continues to
|
||||
/// produce more messages every `duration` after that.
|
||||
pub fn every(
|
||||
duration: std::time::Duration,
|
||||
) -> Subscription<std::time::Instant> {
|
||||
subscription::from_recipe(Every(duration))
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Every(std::time::Duration);
|
||||
|
||||
impl subscription::Recipe for Every {
|
||||
type Output = std::time::Instant;
|
||||
|
||||
fn hash(&self, state: &mut Hasher) {
|
||||
use std::hash::Hash;
|
||||
|
||||
std::any::TypeId::of::<Self>().hash(state);
|
||||
self.0.hash(state);
|
||||
}
|
||||
|
||||
fn stream(
|
||||
self: Box<Self>,
|
||||
_input: subscription::EventStream,
|
||||
) -> futures::stream::BoxStream<'static, Self::Output> {
|
||||
use futures::stream::StreamExt;
|
||||
|
||||
async_std::stream::interval(self.0)
|
||||
.map(|_| std::time::Instant::now())
|
||||
.boxed()
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue