Remove async-std support (RIP)

This commit is contained in:
Héctor Ramón Jiménez 2025-04-02 10:45:27 +02:00
parent 57cb14ce38
commit 91996372cb
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
8 changed files with 13 additions and 104 deletions

View file

@ -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"

View file

@ -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)?;