Mojo trait
Truncable
The Truncable trait describes a type that defines a truncation operation.
Types that conform to Truncable will work with the builtin trunc
function. The truncation operation always returns the same type as the
input.
For example:
from math import Truncable, trunc
@fieldwise_init
struct Complex(Truncable, ImplicitlyCopyable):
var re: Float64
var im: Float64
fn __trunc__(self) -> Self:
return Self(trunc(self.re), trunc(self.im))Implemented traits
AnyType,
ImplicitlyDestructible
comptime members
__del__is_trivial
comptime __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
__trunc__
__trunc__(self: _Self) -> _Self
Return the truncated Int value, which is itself.
Returns:
_Self: The Int value itself.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!