Impl aliases provide alternative names for existing implementations (impls). They do not create new implementations; they simply refer to an existing one, potentially with concrete generic arguments applied.
Use cases include:
- Providing shorter or more descriptive names for complex implementations.
- Re-exporting implementations from other modules.
- Fixing specific generic arguments of an implementation while leaving others generic.
Syntax:
impl ImplAliasName<GenericParams> = path::to::Impl<GenericArgs>;
ImplAliasName: The new name for the implementation.GenericParams: (Optional) Generic parameters introduced by the alias.path::to::Impl: The path to the existing implementation or another alias.GenericArgs: (Optional) Concrete generic arguments passed to the underlying implementation.
trait Pow<T> {
fn pow(base: T, exp: u32) -> T;
}
impl AnyAlgebraPow<T, impl AlgImpl: Algebra<T>> of Pow<T> {
fn pow(base: T, exp: u32) -> T {
// Implementation details.
base
}
}
// Impl alias for Pow of felt252.
impl FeltPow = AnyAlgebraPow<felt252, FeltAlgebra>;
fn main() {
// Call through the trait name.
let x = Pow::pow(5, 3);
// Call through the impl alias name.
let y = FeltPow::pow(5, 3);
}