IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: 1.0
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

trait_downcast[T: TrivialRegisterPassable, //, Trait: AnyTrait[AnyType]](var src: T) -> 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.

Parameters:

Args:

  • src (T): The value to downcast.

Returns:

T(Trait): The downcasted value.

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.

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.