pub trait Type {
const SIGNATURE: &'static Signature;
}Expand description
Trait implemented by all serializable types.
This very simple trait provides the signature for the implementing type. Since the D-Bus type
system relies on these signatures, our serialization and deserialization API requires this
trait in addition to serde::Serialize and serde::de::Deserialize, respectively.
Implementation is provided for all the basic types and blanket implementations
for common container types, such as, arrays, slices, tuples, Vec and
std::collections::HashMap. For easy implementation for custom types, use Type derive macro
from zvariant_derive crate.
If your type’s signature cannot be determined statically, you should implement the
DynamicType trait instead, which is otherwise automatically implemented if you implement
this trait.
Required Associated Constants§
Sourceconst SIGNATURE: &'static Signature
const SIGNATURE: &'static Signature
The signature for the implementing type, in parsed format.
§Example
use std::collections::HashMap;
use zvariant::{Type, signature::{Child, Signature}};
assert_eq!(u32::SIGNATURE, &Signature::U32);
assert_eq!(String::SIGNATURE, &Signature::Str);
assert_eq!(
<(u32, &str, u64)>::SIGNATURE,
&Signature::static_structure(&[&Signature::U32, &Signature::Str, &Signature::U64]),
);
assert_eq!(
<(u32, &str, &[u64])>::SIGNATURE,
&Signature::static_structure(&[
&Signature::U32,
&Signature::Str,
&Signature::Array(Child::Static { child: &Signature::U64 }),
]),
);
assert_eq!(
<HashMap<u8, &str>>::SIGNATURE,
&Signature::static_dict(&Signature::U8, &Signature::Str),
);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.