pub trait Type {
// Required method
fn signature() -> Signature<'static>;
}
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 Serialize
and Deserialize
, respectively.
Implementation is provided for all the basic types and blanket implementations for common
container types, such as, arrays, slices, tuples, Vec
and 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 Methods§
sourcefn signature() -> Signature<'static>
fn signature() -> Signature<'static>
Get the signature for the implementing type.
§Example
use std::collections::HashMap;
use zvariant::Type;
assert_eq!(u32::signature(), "u");
assert_eq!(String::signature(), "s");
assert_eq!(<(u32, &str, u64)>::signature(), "(ust)");
assert_eq!(<(u32, &str, &[u64])>::signature(), "(usat)");
assert_eq!(<HashMap<u8, &str>>::signature(), "a{ys}");