Object

Derive Macro Object 

Source
#[derive(Object)]
{
    // Attributes available to this derive:
    #[wayland]
}
Expand description

Generate Object impls for an enum type.

Generates a Object impl that dispatches to the Object implemented by the enum variants.

Depending on the setting of context, this can be used to generate either a generic or a concrete implementation of Object.

If context is not set, the generated implementation will be generic over the the context type (i.e. the type parameter Ctx of Object). If your object types are generic over the context type too, then you must name that generic parameter Ctx too.

If context is set, the generated implementation will be an impl of Object<$context>.

All variants’ Object impls must have the same error type.

This also derives impl From<Variant> for Enum for each of the variants

§Examples

For the generic case:

#[derive(Object)]
pub enum Objects<Ctx> { // this must be called `Ctx`
    Display(MyDisplayObject<Ctx>),
}

This will generate:

impl<Ctx> Object<Ctx> for Objects<Ctx> {
    // ..
}
impl<Ctx> From<MyDisplayObject<Ctx>> for Object<Ctx> {
    // ..
}

If the generic parameter is named something else, such as T, this will be generated:

impl<Ctx, T> Object<Ctx> for Objects<T> {
    // ..
}

§Attributes

Accept attributes in the form of #[wayland(...)].

  • crate - The path to the runa-core crate. “runa_core” by default.
  • context - See above