[][src]Macro rustbus::dbus_variant_var

macro_rules! dbus_variant_var {
    ($vname: ident, $($name: ident => $typ: path);+) => { ... };
}

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

  1. 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);