Mojo trait
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
Required methods
__trunc__
__trunc__(self: _Self) -> _Self
Return the truncated Int value, which is itself.
Returns:
_Self: The Int value itself.