Macro rustbus::dbus_variant_sig
source · macro_rules! dbus_variant_sig { ($vname: ident, $($name: ident => $typ: path);+) => { ... }; }
Expand description
NOTE: There are derive proc-macros for enums. These should preferably be used because these macros are likely to be deprecated and removed. The proc-macros do not yet support the Catchall cases. So if you need those feel free to keep using these macros for now. Deprecation/Removal will only take place once the proc-macros are functionally equal to these macros.
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 = std::collections::HashMap<String, (i32, u8, (u64, MyVariant))>;
type Struct = (u32, u32, MyVariant);
dbus_variant_sig!(MyVariant, CaseMap => Map; CaseStruct => Struct);
And it will generate an enum like this:
enum MyVariant {
CaseMap(Map),
CaseStruct(Struct),
Catchall(rustbus::signature::Type),
}
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! If you want to have a case for a signature you need to make it explicitly.
Current limitations
- References like &str are not supported