46 stable releases (3 major)

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

#1915 in Encoding

Download history 171744/week @ 2024-07-29 170445/week @ 2024-08-05 159685/week @ 2024-08-12 160179/week @ 2024-08-19 169048/week @ 2024-08-26 168770/week @ 2024-09-02 158476/week @ 2024-09-09 148084/week @ 2024-09-16 170097/week @ 2024-09-23 166305/week @ 2024-09-30 171811/week @ 2024-10-07 174553/week @ 2024-10-14 177684/week @ 2024-10-21 179892/week @ 2024-10-28 193976/week @ 2024-11-04 176856/week @ 2024-11-11

740,490 downloads per month
Used in 483 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
~60K SLoC