https://github.com/grantshandy/disk-persist
https://github.com/grantshandy/disk-persist
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/grantshandy/disk-persist
- Owner: grantshandy
- License: mit
- Created: 2022-07-15T01:52:09.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-07-15T02:49:23.000Z (almost 3 years ago)
- Last Synced: 2025-03-11T05:48:16.946Z (2 months ago)
- Language: Rust
- Size: 7.81 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Disk Persist
[](https://github.com/grantshandy/disk-persist/actions)
[](https://crates.io/crates/disk-persist)
[](https://docs.rs/disk-persist)
[](https://opensource.org/licenses/MIT)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](https://serde.rs/)'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:
```rust
use serde::{Deserialize, Serialize};...
#[derive(Serialize, Deserialize, Debug)]
struct Data {
name: String,
age: u8,
}
```Write it to disk:
```rust
let persist: DiskPersist = 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:
```rust
let persist: DiskPersist = DiskPersist::init("disk-persist-example").unwrap();println!("{:#?}", persist.read().unwrap());
```Outputs:
```
Some(
Data {
name: "John Doe",
age: 45,
},
)
```