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 automatic 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. - An
InferableBrand_{hash}impl for the target type, mapping it back to the brand. This enables brand inference for free functions likemap,bind, etc.
The InferableBrand impl is suppressed when:
#[no_inferable_brand]is present (for types with multiple brands).- The target type is a projection (contains
Apply!or::). - Multiple associated types are defined.
§Attributes
Inside the impl_kind! block, you can use these attributes:
#[no_inferable_brand]: SuppressesInferableBrandimpl generation. Use this for types reachable through multiple brands (e.g.,Resultat arity 1).#[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... for Option<A> {
type Brand = OptionBrand;
}ⓘ
// 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_... for Result<A, E> {
type Brand = ResultBrand<E>;
}ⓘ
// Suppressing InferableBrand generation for multi-brand types
impl_kind! {
#[no_inferable_brand]
impl<E> for ResultErrAppliedBrand<E> {
type Of<'a, A: 'a>: 'a = Result<A, E>;
}
}
// Expanded code (only Kind impl, no InferableBrand)
impl<E> Kind_... for ResultErrAppliedBrand<E> {
type Of<'a, A: 'a>: 'a = Result<A, E>;
}ⓘ
// 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>;
}