Keep old data

This commit is contained in:
Alex Auvolat
2021-04-05 20:33:24 +02:00
parent 595dc0ed0d
commit f11bd80d2a
2 changed files with 31 additions and 5 deletions
+11 -1
View File
@@ -1,7 +1,7 @@
use std::io::{Read, Write};
use std::path::PathBuf;
use tokio::io::AsyncWriteExt;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use serde::{Deserialize, Serialize};
@@ -51,6 +51,16 @@ where
Ok(())
}
pub async fn load_async(&self) -> Result<T, Error> {
let mut file = tokio::fs::File::open(&self.path).await?;
let mut bytes = vec![];
file.read_to_end(&mut bytes).await?;
let value = rmp_serde::decode::from_read_ref(&bytes[..])?;
Ok(value)
}
pub async fn save_async(&self, t: &T) -> Result<(), Error> {
let bytes = rmp_to_vec_all_named(t)?;