Apply!() { /* proc-macro */ }Expand description
Applies a brand to type arguments.
This macro projects a brand type to its concrete type using the appropriate Kind trait. It uses named parameters syntax.
§Modes
The macro supports two modes of operation:
- Unified Signature Mode (Recommended): Uses a single
signatureparameter to specify both the schema (for Kind trait name generation) and the concrete values (for projection). - Explicit Kind Mode (Advanced): Uses an explicit
kindparameter along with separatelifetimesandtypesparameters.
§Parameters
brand: (Required) The brand type (e.g.,OptionBrand).signature: (Mode 1) The unified signature containing both schema and values.kind: (Mode 2) An explicit Kind trait to use.lifetimes: (Mode 2) Lifetime arguments to apply. Required withkind.types: (Mode 2) Type arguments to apply. Required withkind.
§Unified Signature Syntax
The signature parameter uses a syntax similar to a function signature:
(param1, param2, ...) -> OutputBounds
- Lifetimes: Specified as
'a,'static, etc. - Types: Specified as
TypeorType: Bounds.- The
Typepart is used as the concrete value for projection. - The
Boundspart (optional) is used for Kind trait name generation.
- The
§Examples
§Unified Signature Mode (Recommended)
ⓘ
// Applies MyBrand to lifetime 'static and type String.
// The schema is inferred as: 1 lifetime, 1 type parameter (unbounded).
type Concrete = Apply!(
brand: MyBrand,
signature: ('static, String)
);
// Applies MyBrand to a generic type T with bounds.
// The schema is inferred as: 1 type parameter with Clone bound.
type Concrete = Apply!(
brand: MyBrand,
signature: (T: Clone)
);
// Complex example with lifetimes, types, and output bounds.
type Concrete = Apply!(
brand: MyBrand,
signature: ('a, T: Clone + Debug) -> Display
);§Explicit Kind Mode (Advanced)
Use this mode when you need to specify a custom Kind trait directly.
ⓘ
// Applies OptionBrand using an explicit Kind trait.
type Concrete = Apply!(
brand: OptionBrand,
kind: SomeKind,
lifetimes: ('a),
types: (String)
);