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:
-
AnyType: The most basic trait that all types extend by default. Types with this trait have no destructor and no lifetime management. -
ImplicitlyDestructible: 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.
These traits are built into Mojo and do not need to be imported.
comptime values
__SomeImpl
comptime __SomeImpl[Trait: AnyTrivialRegType, T: Trait] = T
Parameters
- Trait (
AnyTrivialRegType): - T (
Trait):
Some
comptime 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): The trait or trait composition that the argument type must implement.
UnknownDestructibility
comptime UnknownDestructibility = AnyType
Temporary alias for types that can be implicitly destroyed.
Deprecated: 'UnknownDestructibility' is deprecated, use 'AnyType' instead
Traits
-
AnyType: The most basic trait that all Mojo types extend by default. -
ImplicitlyDestructible: A trait for types that require lifetime management through destructors.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!