Crates.io | vow |
lib.rs | vow |
version | |
source | src |
created_at | 2024-10-08 07:53:48.100703 |
updated_at | 2024-10-09 05:07:16.056469 |
description | Serde <--> File made easy |
homepage | |
repository | https://github.com/George-Miao/vow |
max_upload_size | |
id | 1400873 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Serde <--> File
made easy.
Vow is a simple but generic data binding library for Rust. It allows you to bind any type that implements Serialize + DeserializeOwned
to a file, and keeps the file up-to-date while supporting multiple backends (both synchronous and asynchronous).
Supported backends:
Supported formats:
json
toml
use serde::{Deserialize, Serialize};
use vow::*;
#[derive(Serialize, Deserialize)]
struct MyData {
a: i32,
b: String,
}
#[compio::main]
async fn main() {
let mut data = VowAsync::open_compio("/tmp/data.json")
.default(MyData {
a: 42,
b: "hello".to_string(),
})
.overwrite_local()
.build()
.await
.unwrap();
assert_eq!(data.a, 42);
data.update(|data| data.a += 1).await.unwrap();
assert_eq!(data.a, 43);
data.update(|data| data.b += " world!").await.unwrap();
assert_eq!(data.b, "hello world!");
data.map(|data| MyData {
b: String::new(),
..data
})
.await
.unwrap();
assert_eq!(data.b, "");
}
For more examples, see the examples
directory.