impl_kind!() { /* proc-macro */ }Expand description
Implements a Kind trait and its InferableBrand trait for a brand.
This macro simplifies the implementation of a generated Kind trait for a specific
brand type, and also generates the InferableBrand impl that enables closure-directed brand
inference in dispatch functions. It infers the correct Kind trait to implement based
on the signature of the associated types provided in the block.
The signature (names, parameters, and bounds) of the associated types must match
the definition used in trait_kind! or Kind! to ensure the correct trait is implemented.
§Syntax
impl_kind! {
// Optional impl generics
impl<Generics> for BrandType
// Optional where clause
where Bounds
{
type AssocName<Params> = ConcreteType;
// ... more associated types
}
}Generics: Optional generic parameters for the implementation.BrandType: The brand type to implement the Kind for.Bounds: Optional where clause bounds.Associated Types: The associated type assignments (e.g.,type Of<A> = Option<A>;).
§Generates
- An implementation of the appropriate
Kind_{hash}trait for the brand. - A
InferableBrand_{hash}impl for the target type withtype Marker = Val, enabling closure-directed brand inference for both single-brand and multi-brand types.
The InferableBrand impl is generated for ALL brands (including multi-brand types).
Projection types and multiple-associated-type definitions do suppress it.
§Attributes
Inside the impl_kind! block, you can use these attributes:
#[multi_brand]: Marks this brand as sharing its target type with other brands. Does NOT suppressInferableBrandimpl generation.#[document_default]: Marks this associated type as the default for resolving bareSelfin the generated documentation for this brand within the module.
§Examples
// Invocation
impl_kind! {
for OptionBrand {
#[document_default]
type Of<A> = Option<A>;
}
}
// Expanded code (Kind impl + InferableBrand impl)
impl Kind_a1b2... for OptionBrand {
type Of<A> = Option<A>;
}
impl<A> InferableBrand_a1b2...<OptionBrand, A> for Option<A> {
type Marker = Val;
}// Invocation with impl generics
impl_kind! {
impl<E> for ResultBrand<E> {
type Of<A> = Result<A, E>;
}
}
// Expanded code
impl<E> Kind_... for ResultBrand<E> {
type Of<A> = Result<A, E>;
}
impl<A, E> InferableBrand_...<ResultBrand<E>, A> for Result<A, E> {
type Marker = Val;
}// Multi-brand type: InferableBrand still generated
impl_kind! {
#[multi_brand]
impl<E> for ResultErrAppliedBrand<E> {
type Of<'a, A: 'a>: 'a = Result<A, E>;
}
}
// Expanded code (Kind impl + InferableBrand impl)
impl<E> Kind_... for ResultErrAppliedBrand<E> {
type Of<'a, A: 'a>: 'a = Result<A, E>;
}
impl<'a, A: 'a, E> InferableBrand_...<'a, ResultErrAppliedBrand<E>, A>
for Result<A, E>
{
type Marker = Val;
}// Multiple associated types: InferableBrand skipped automatically
impl_kind! {
impl<E> for MyBrand<E> where E: Clone {
type Of<A> = MyType<A, E>;
type SendOf<A> = MySendType<A, E>;
}
}
// Expanded code (only Kind impl)
impl<E> Kind_... for MyBrand<E> where E: Clone {
type Of<A> = MyType<A, E>;
type SendOf<A> = MySendType<A, E>;
}