Crates.io | disk-persist |
lib.rs | disk-persist |
version | 0.1.0 |
source | src |
created_at | 2022-07-15 02:49:57.334084 |
updated_at | 2022-07-15 02:49:57.334084 |
description | A library that makes it very easy for your application to keep data inbetween executions |
homepage | https://grantshandy.github.io/ |
repository | https://github.com/grantshandy/disk-persist/ |
max_upload_size | |
id | 625998 |
size | 14,927 |
A library that makes it very easy for your application to keep data inbetween executions. It can (very quickly) read and write any data structure that implements serde's Serialize
and Deserialize
to disk. It automatically saves the information to either the user's cache folder or any other path that you specify.
Default Location:
Platform | Value | Example |
---|---|---|
Linux | $XDG_CACHE_HOME or $HOME /.cache |
/home/user/.cache |
macOS | $HOME /Library/Caches |
/Users/User/Library/Caches |
Windows | {FOLDERID_LocalAppData} |
C:\Users\User\AppData\Local |
Create our data:
use serde::{Deserialize, Serialize};
...
#[derive(Serialize, Deserialize, Debug)]
struct Data {
name: String,
age: u8,
}
Write it to disk:
let persist: DiskPersist<Data> = DiskPersist::init("disk-persist-example").unwrap();
let data = Data {
name: "John Doe".to_string(),
age: 45,
};
persist.write(&data).unwrap();
Then read it at any time:
let persist: DiskPersist<Data> = DiskPersist::init("disk-persist-example").unwrap();
println!("{:#?}", persist.read().unwrap());
Outputs:
Some(
Data {
name: "John Doe",
age: 45,
},
)