For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).
trait_downcast
def trait_downcast[T: AnyType, //, Trait: AnyTrait[AnyType]](ref src: T) -> ref[src] T(Trait)
Downcast a parameter input type T and rebind the type such that the return value's type conforms the provided Trait. If T, after resolving to a concrete type, does not actually conform to Trait, a compilation error would occur.
Deprecated: use conforms_to(type_of(src), Trait) instead in a where clause or comptime assert
Parameters:
- T (
AnyType): The original type. - Trait (
AnyTrait[AnyType]): The trait to downcast into.
Args:
- src (
T): The value to downcast.
Returns:
ref[src] T(Trait): The downcasted value.