Crates.io | gvariant |
lib.rs | gvariant |
version | 0.5.0 |
source | src |
created_at | 2020-05-29 01:25:27.837852 |
updated_at | 2022-05-10 21:38:24.658543 |
description | A pure-rust implementation of the GVariant serialisation format |
homepage | https://github.com/wmanley/gvariant-rs/ |
repository | https://github.com/wmanley/gvariant-rs/ |
max_upload_size | |
id | 247223 |
size | 141,089 |
A pure-rust implementation of the GVariant serialisation format intended for fast reading of in-memory buffers.
let string = gv!("s").from_bytes("It works!\0");
assert_eq!(string, "It works!");
Module documentation with examples.
Add this to your Cargo.toml
:
[dependencies]
gvariant = "0.5"
Example: read an ostree dirtree file and print the listing:
use gvariant::{gv, Marker, Structure};
use std::error::Error;
fn ostree_ls(filename: &std::path::Path) -> Result<(), Box<dyn Error>> {
// Read the data into the buffer and interpret as an OSTree tree:
let tree = gv!("(a(say)a(sayay))").deserialize(std::fs::File::open(filename)?)?;
// (a(say)a(sayay)) is a structure, so tree implements gvariant::Structure,
// and we can turn it into a tuple:
let (files, dirs) = tree.to_tuple();
// Print the contents
for s in dirs {
let (filename, tree_checksum, meta_checksum) = s.to_tuple();
println!(
"{} {} {}/",
hex::encode(tree_checksum),
hex::encode(meta_checksum),
filename
)
}
for f in files {
let (filename, checksum) = f.to_tuple();
println!("{} {}", hex::encode(checksum), filename)
}
Ok(())
}
Build with:
cargo build
Run tests:
cargo test
Clippy linting:
cargo clippy
Fuzz testing:
RUSTFLAGS='-C overflow-checks=on' ASAN_OPTIONS="detect_leaks=0" cargo +nightly fuzz run --release fuzz_target_1
This project is licensed under either of
at your option.