trait_kind!() { /* proc-macro */ }Expand description
Defines a new Kind trait.
This macro generates a trait definition for a Higher-Kinded Type signature.
§Syntax
ⓘ
trait_kind!(
type AssocName<Params>: Bounds;
// ...
)Associated Types: A list of associated type definitions (e.g.,type Of<T>;) that define the signature of the Kind.
§Generates
Two public trait definitions with unique names derived from the signature:
Kind_{hash}: The HKT trait with the specified associated types.InferableBrand_{hash}: A reverse-mapping trait for brand inference, with a blanketimpl for &T. Both share the same content hash.
§Examples
ⓘ
// Invocation
trait_kind!(type Of<T>;);
// Expanded code
pub trait Kind_a1b2... {
type Of<T>;
}
pub trait InferableBrand_a1b2... {
type Brand: Kind_a1b2...;
}
impl<T: InferableBrand_a1b2... + ?Sized> InferableBrand_a1b2... for &T {
type Brand = T::Brand;
}ⓘ
// Invocation
trait_kind!(type Of<'a, T: Display>: Debug;);
// Expanded code (same pattern: Kind trait + InferableBrand trait + blanket ref impl)
pub trait Kind_cdef... {
type Of<'a, T: Display>: Debug;
}
pub trait InferableBrand_cdef... {
type Brand: Kind_cdef...;
}
impl<T: InferableBrand_cdef... + ?Sized> InferableBrand_cdef... for &T { ... }