[][src]Macro wayland_client::event_enum

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 iterators. It is used like so:

This example is not tested
event_enum!(
    MyEnum |
    Pointer => WlPointer,
    Keyboard => WlKeyboard,
    Surface => WlSurface
);

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

This example is not tested
pub enum MyEnum {
    Pointer { event: WlPointer::Event, object: WlPointer },
    Keyboard { event: WlKeyboard::Event, object: WlKeyboard },
    Surface { event: WlSurface::Event, object: WlSurface }
}

It will also generate the appropriate From<_> implementation so that a Sink<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:

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

will generate the following enum:

This example is not tested
pub enum MyEnum {
    Pointer { event: WlPointer::Event, object: WlPointer },
    Keyboard { event: WlKeyboard::Event, object: WlKeyboard },
    Surface { event: WlSurface::Event, object: 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 Sink<MyEnum>.