Macro wayland_client::event_enum[][src]

macro_rules! event_enum {
    ($enu:ident | $($evt_name:ident => $iface:ty),*) => { ... };
    ($enu:ident | $($evt_name:ident => $iface:ty),* | $($name:ident => $value:ty),*) => { ... };
}

Generate an enum joining several objects events

This macro allows you to easily create a enum type for use with your message Filters. It is used like so:

event_enum!(
    MyEnum |
    Pointer => WlPointer,
    Keyboard => WlKeyboard,
    Surface => WlSurface
);

This will generate the following enum, unifying the events from each of the provided interface:

pub enum MyEnum {
    Pointer { event: WlPointer::Event, object: Main<WlPointer> },
    Keyboard { event: WlKeyboard::Event, object: Main<WlKeyboard> },
    Surface { event: WlSurface::Event, object: Main<WlSurface> }
}

It will also generate the appropriate From<_> implementation so that a Filter<MyEnum> can be used as an implementation for WlPointer, WlKeyboard and WlSurface.

If you want to add custom messages to the enum, the macro also supports it:

event_enum!(
    MyEnum |
    Pointer => WlPointer,
    Keyboard => WlKeyboard,
    Surface => WlSurface |
    MyMessage => SomeType,
    OtherMessage => OtherType
);

will generate the following enum:

pub enum MyEnum {
    Pointer { event: WlPointer::Event, object: Main<WlPointer> },
    Keyboard { event: WlKeyboard::Event, object: Main<WlKeyboard> },
    Surface { event: WlSurface::Event, object: Main<WlSurface> },
    MyMessage(SomeType),
    OtherMessage(OtherType)
}

as well as implementations of From<SomeType> and From<OtherType>, so that these types can directly be provided into a Filter<MyEnum>.