work
This commit is contained in:
16
src/rsc.rs
16
src/rsc.rs
@@ -1,12 +1,10 @@
|
||||
use std::{
|
||||
fs::{self, File},
|
||||
io::Write,
|
||||
path::Path,
|
||||
};
|
||||
|
||||
use directories_next::ProjectDirs;
|
||||
use ed25519_dalek::VerifyingKey;
|
||||
|
||||
use crate::net::BINCODE_CONFIG;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct DataDir {
|
||||
@@ -21,7 +19,7 @@ impl Default for DataDir {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait DataRsc: bincode::Encode + bincode::Decode<()> + Default {
|
||||
pub trait DataRsc: bitcode::Encode + bitcode::DecodeOwned + Default {
|
||||
fn path() -> &'static str;
|
||||
}
|
||||
|
||||
@@ -33,8 +31,8 @@ impl DataDir {
|
||||
pub fn load<T: DataRsc>(&self) -> T {
|
||||
let path = self.get().join(T::path());
|
||||
match fs::read(path) {
|
||||
Ok(bytes) => match bincode::decode_from_slice(&bytes, BINCODE_CONFIG) {
|
||||
Ok((data, _)) => data,
|
||||
Ok(bytes) => match bitcode::decode(&bytes) {
|
||||
Ok(data) => data,
|
||||
Err(_) => todo!(),
|
||||
},
|
||||
Err(_) => T::default(),
|
||||
@@ -45,8 +43,8 @@ impl DataDir {
|
||||
let dir = self.get();
|
||||
fs::create_dir_all(dir).unwrap();
|
||||
let mut file = File::create(dir.join(T::path())).unwrap();
|
||||
bincode::encode_into_std_write(data, &mut file, BINCODE_CONFIG).unwrap();
|
||||
// TODO: used to use encode_into_std_write from bincode here
|
||||
let data = bitcode::encode(data);
|
||||
file.write_all(&data).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DevicePublicKey(VerifyingKey);
|
||||
|
||||
Reference in New Issue
Block a user