Mojo module
anytype
Defines the core traits for object lifetime management in Mojo.
This module provides the foundational traits that define how objects are created, managed and destroyed in Mojo:
- 
UnknownDestructibility: The most basic trait that all types extend by default. Types with this trait have no destructor and no lifetime management.
- 
AnyType: The base trait for types that require lifetime management through destructors. Any type that needs cleanup when it goes out of scope should implement this trait.
- 
ImplicitlyDestructible: An alias forAnyTypeto help with the transition to linear types. Use this when you want to be explicit about a type having a destructor.
These traits are built into Mojo and do not need to be imported.
Aliases
__SomeImpl
alias __SomeImpl[Trait: AnyTrivialRegType, T: Trait] = T
Parameters
- Trait (AnyTrivialRegType):
- T (Trait):
ImplicitlyDestructible
alias ImplicitlyDestructible = AnyType
Some
alias Some[Trait: AnyTrivialRegType] = alias[T: Trait] T
An alias allowing users to tersely express that a function argument is an instance of a type that implements a trait or trait composition.
For example, instead of writing
fn foo[T: Intable, //](x: T) -> Int:
    return x.__int__()one can write:
fn foo(x: Some[Intable]) -> Int:
    return x.__int__()Parameters
- Trait (AnyTrivialRegType):
Traits
- AnyType: A trait for types that require lifetime management through destructors.
- UnknownDestructibility: The most basic trait that all Mojo types extend by default.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!
