devela::all

Macro type_resource

Source
macro_rules! type_resource {
    ($($name:ident),+ : $inner:ty) => { ... };
    ($($($name:ident),+ : $inner:ty);+ $(;)?) => { ... };
}
Expand description

Defines zero-cost, zero-sized, type-safe resource IDs.

This macro generates zero-sized types associated with an inner ID type. These types enable strong type safety at compile time while adding no runtime overhead.

By associating resources with unique types, the system enforces correct usage of identifiers and reduces errors from mixing unrelated IDs.

Each generated type provides a new constructor method returning a TypeResource instance of the associated inner type.

Unlike type_marker!, which generates purely marker types with no data, type_resource! ties each type to an inner ID type for handling type-safe resources.

ยงExample

type_resource![Id0:u8]; // single definition and resource
type_resource![Id1,Id2:u16]; // multiple definitions, same resource
type_resource![Id3,Id4:u32; Id5:u64; Id6,Id7:i8]; // diferent resources

See also: TypeResource and TypeResourced.