#save #disk #cache #persist

disk-persist

A library that makes it very easy for your application to keep data inbetween executions

1 unstable release

0.1.0 Jul 15, 2022

#1563 in Filesystem

Download history 6/week @ 2024-07-19 6/week @ 2024-09-13 5/week @ 2024-09-20 1/week @ 2024-09-27 11/week @ 2024-10-04 91/week @ 2024-10-11 312/week @ 2024-10-18 308/week @ 2024-10-25 337/week @ 2024-11-01

1,054 downloads per month

MIT license

8KB
108 lines

Disk Persist

CI

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

The Basics

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,
    },
)

Dependencies

~0.6–1.6MB
~31K SLoC