Expand description
§Vow
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
§Example
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.
Structs§
- Vow
- Synchronously binds data to a file.
- VowAsync
- Asynchronously binds data to a file.
- VowBuilder
- Builder for
Vow
.
Enums§
Traits§
- BufFut
- Trait alias for futures returning
(io::Result<()>, Vec<u8>)
- Data
- Trait alias for types that can be serialized and deserialized.
- IoFut
- Trait alias for futures returning
io::Result<T>
- VowFile
- Low-level trait for synchronous file operations
- VowFile
Async - Low-level trait for asynchronous file operations
Type Aliases§
- VowResult
- Result type for vow operations.