impl_kind!() { /* proc-macro */ }Expand description
Implements a Kind trait for a brand.
This macro simplifies the implementation of a generated Kind trait for a specific
brand type. 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
}
}§Parameters
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 trait for the brand.
§Attributes
Inside the impl_kind! block, you can use documentation-specific attributes on associated types:
#[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
impl Kind_... for OptionBrand { // e.g., Kind_a1b2c3d4e5f67890
type Of<A> = Option<A>;
}ⓘ
// Invocation
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>;
}ⓘ
// Invocation
impl_kind! {
impl<E> for MyBrand<E> where E: Clone {
type Of<A> = MyType<A, E>;
type SendOf<A> = MySendType<A, E>;
}
}
// Expanded code
impl<E> Kind_... for MyBrand<E> where E: Clone {
type Of<A> = MyType<A, E>;
type SendOf<A> = MySendType<A, E>;
}ⓘ
// Invocation
// Corresponds to: trait_kind!(type Of<T: Display>;);
impl_kind! {
for DisplayBrand {
// Bounds here are used to infer the correct `Kind` trait name
type Of<T: Display> = DisplayType<T>;
}
}
// Expanded code
impl Kind_... for DisplayBrand {
type Of<T: Display> = DisplayType<T>;
}