Mojo trait
Sized
The Sized trait describes a type that has an integer length (such as a string or array).
Any type that conforms to Sized or
SizedRaising works with the
built-in len() function.
The Sized trait requires a type to implement the __len__()
method. For example:
struct Foo(Sized):
var length: Int
fn __len__(self) -> Int:
return self.lengthYou can pass an instance of Foo to the len() function to get its
length:
var foo = Foo(42)
print(len(foo) == 42)TrueNote: If the __len__() method can raise an error, use the
SizedRaising trait instead.
Implemented traits
AnyType,
UnknownDestructibility
Aliases
__del__is_trivial
alias __del__is_trivial
A flag (often compiler generated) to indicate whether the implementation of __del__ is trivial.
The implementation of __del__ is considered to be trivial if:
- The struct has a compiler-generated trivial destructor and all its fields
have a trivial
__del__method.
In practice, it means that the __del__ can be considered as no-op.
Required methods
__len__
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!