aboutsummaryrefslogtreecommitdiff
path: root/src/util/persister.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2021-04-05 20:33:24 +0200
committerAlex Auvolat <alex@adnab.me>2021-04-05 20:33:24 +0200
commitf11bd80d2a0b8ba0c108deab1293daa31109ce5f (patch)
tree1feb09f40f0c61201ea2a7c6570bef817c40f0ee /src/util/persister.rs
parent595dc0ed0d6994cbe0f628b41df85f44c576dc64 (diff)
downloadgarage-f11bd80d2a0b8ba0c108deab1293daa31109ce5f.tar.gz
garage-f11bd80d2a0b8ba0c108deab1293daa31109ce5f.zip
Keep old data
Diffstat (limited to 'src/util/persister.rs')
-rw-r--r--src/util/persister.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/util/persister.rs b/src/util/persister.rs
index f4e8cd72..93b7cdf4 100644
--- a/src/util/persister.rs
+++ b/src/util/persister.rs
@@ -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)?;