Macro typeinfo::def [] [src]

macro_rules! def {
    ($($(#[$attr:meta])* struct $s:ident { $($i:ident: $t:ty),+$(,)* })*) => { ... };
    ($($(#[$attr:meta])* pub struct $s:ident { $($i:ident: $t:ty),+$(,)* })*) => { ... };
    ($($(#[$attr:meta])* pub struct $s:ident { $(pub $i:ident: $t:ty),+$(,)* })*) => { ... };
    (@impl $s:ident { $($i:ident: $t:ty),+ }) => { ... };
}

Compound type constructor that implements TypeInfo trait automatically.

This macro can be used anywhere a normal struct definition can be placed, supports visibility qualifiers, struct attributes, nested datatypes and multiple struct definitions inside one invocation.

def! defines the type as given, derives Clone and Copy, and implements the TypeInfo trait so the type information is readily accessible at runtime.

Note: due to certain limitations of the macro system, a single macro invocation may only contain definitions where both fields and structs have the same visibility qualifier.

Examples

def! {
    #[derive(Debug)]
    pub struct Color {
        r: u8,
        g: u8,
        b: u8,
    }

    pub struct Palette {
        colors: [Color; 16]
    }
}