Crate zvariant_derive
source ·Expand description
§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::{EncodingContext, from_slice, to_bytes, Type};
use serde::{Deserialize, Serialize};
use byteorder::LE;
#[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 = EncodingContext::<LE>::new_dbus(0);
let encoded = to_bytes(ctxt, &s).unwrap();
let decoded: Struct = from_slice(&encoded, ctxt).unwrap();
assert_eq!(decoded, s);
Derive Macros§
- Adds
Deserialize
implementation to structs to be deserialized froma{sv}
type. - Implements conversions for your type to/from
OwnedValue
. - Adds
Serialize
implementation to structs to be serialized asa{sv}
type. - Derive macro to add
Type
implementation to structs and enums. - TypeDictDeprecatedDerive macro to add
Type
implementation to structs serialized asa{sv}
type. - Implements conversions for your type to/from
Value
.