Update toml

This commit is contained in:
asonix 2024-02-11 19:20:32 -06:00
parent a2abc146f4
commit 21ffc4111e
3 changed files with 376 additions and 245 deletions

603
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -18,6 +18,6 @@ reqwest = { version = "0.11", default-features = false, features = [
] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
toml = "0.5"
toml = "0.8"
tokio = { version = "1", features = ["full"] }
url = { version = "2.0", features = ["serde"] }

View file

@ -94,27 +94,27 @@ impl Mastodon {
async fn read_token(path: impl AsRef<Path>) -> Result<Token> {
let mut file = File::open(path).await?;
let mut contents = vec![];
file.read_to_end(&mut contents).await?;
let mut contents = String::new();
file.read_to_string(&mut contents).await?;
let token: Token = toml::from_slice(&contents)?;
let token: Token = toml::from_str(&contents)?;
Ok(token)
}
async fn write_token(path: impl AsRef<Path>, token: &Token) -> Result<()> {
let token_bytes = toml::to_vec(token)?;
let token_bytes = toml::to_string(token)?;
let mut file = File::create(path).await?;
file.write_all(&token_bytes).await?;
file.write_all(token_bytes.as_bytes()).await?;
Ok(())
}
impl Config {
async fn open(path: impl AsRef<Path>) -> Result<Self> {
let mut file = File::open(path).await?;
let mut contents = vec![];
file.read_to_end(&mut contents).await?;
let mut contents = String::new();
file.read_to_string(&mut contents).await?;
let config: Config = toml::from_slice(&contents)?;
let config: Config = toml::from_str(&contents)?;
Ok(config)
}