Macro rustbus::dbus_variant_var
source · macro_rules! dbus_variant_var { ($vname: ident, $($name: ident => $typ: ty);+) => { ... }; }
Expand description
This macro provides a convenient way to create enums to represent relatively simple Variants, with fitting marshal/unmarshal implementations. It can be used like this:
ⓘ
type Map<'buf> = std::collections::HashMap<String, (i32, u8, (u64, MyVariant<'buf>))>;
type Struct<'buf> = (u32, u32, MyVariant<'buf>);
dbus_variant_var!(MyVariant2, CaseMap => Map<'buf>; CaseStruct => Struct<'buf>);
And it will generate an enum like this:
ⓘ
enum MyVariant<'buf> {
CaseMap(Map<'buf>),
CaseStruct(Struct<'buf>),
Catchall(rustbus::wire::unmarshal::traits::Variant<'buf>),
}
The Catchall
case is used for unmarshalling, when encountering a Value that did not match any of the other cases. The generated marshal impl will
refuse to marshal the Catchall case!.
Current limitations
- References like &str are supported, if you use a type def like this:
type StrRef<'buf> = &'buf str;
dbus_variant_var!(MyVariant, String => StrRef<'buf>; V2 => i32; Integer => u32);