46 stable releases (3 major)

new 5.1.0 Nov 2, 2024
4.2.0 Jul 19, 2024
4.0.2 Feb 25, 2024
3.15.2 Feb 25, 2024
2.0.0 May 22, 2020

#41 in #derive-deserialize

Download history 168815/week @ 2024-07-18 173614/week @ 2024-07-25 164201/week @ 2024-08-01 171423/week @ 2024-08-08 157474/week @ 2024-08-15 164846/week @ 2024-08-22 164444/week @ 2024-08-29 170526/week @ 2024-09-05 151827/week @ 2024-09-12 154690/week @ 2024-09-19 172016/week @ 2024-09-26 173662/week @ 2024-10-03 165969/week @ 2024-10-10 182128/week @ 2024-10-17 178640/week @ 2024-10-24 185935/week @ 2024-10-31

745,719 downloads per month
Used in 490 crates (7 directly)

MIT license

105KB
2K SLoC

zvariant_derive

This crate provides derive macros helpers for zvariant. The zvariant crate re-exports these macros for your convenience so you do not need to use this crate directly.

Status: Stable.

Example code

use zvariant::{serialized::Context, to_bytes, Type, LE};
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize, Type, PartialEq, Debug)]
struct Struct<'s> {
    field1: u16,
    field2: i64,
    field3: &'s str,
}

assert_eq!(Struct::SIGNATURE, "(qxs)");
let s = Struct {
    field1: 42,
    field2: i64::max_value(),
    field3: "hello",
};
let ctxt = Context::new_dbus(LE, 0);
let encoded = to_bytes(ctxt, &s).unwrap();
let decoded: Struct = encoded.deserialize().unwrap().0;
assert_eq!(decoded, s);

Dependencies

~2.3–3MB
~61K SLoC