devela::all

Macro type_marker

Source
macro_rules! type_marker {
    ($(#[$meta:meta])* $name:ident) => { ... };
    ($(#[$meta:meta])* $name:ident < $($gen:ident),+ >) => { ... };
    (
        // a list of types separated by semicolon (;)
        //
        // Arguments:
        // $meta: an optional list of attributes
        // $name: the name of the marker type
        // $gen:  an optional list of generics (>= 1)
        // ;
        $(
            $(#[$meta:meta])*
            $name:ident $( < $($gen:ident),* > )?
        );+ $(;)?
    ) => { ... };
}
Expand description

Defines zero-cost, zero-sized, generic marker IDs.

These marker types carry no runtime data and serve as compile-time indicators of state, configuration, or constraints, helping enforce type-level invariants without introducing runtime overhead.

The macro provides a new constructor method, derives common utility traits (e.g., Clone, Copy, Default, Debug, Display, PartialEq, Eq, PartialOrd, Ord, Hash), and supports defining multiple types at once.

Unlike type_resource!, which ties types to an inner ID, type_marker! generates purely zero-sized marker types.

ยงExample

type_marker![Id0];
type_marker![Id1<A>];
type_marker![Id2<A, B>; Id3<A>; Id4];

type_marker![
    /// supports attributes
    TypeA;

    /// on each type
    #[repr(transparent)]
    TypeB<A, B, C>;
];

impl Id0 { fn hi() {} }
impl<A, B> Id2<A, B> { fn hi() {} }