Mojo trait
IntableRaising
The IntableRaising trait describes a type can be converted to an Int, but the conversion might raise an error.
Any type that conforms to Intable
or IntableRaising can construct an Int.
This trait requires the type to implement the __int__() method, which can
raise an error. For example:
struct Foo(IntableRaising):
var i: Int
fn __int__(self) raises -> Int:
return self.iNow you can construct an Int:
foo = Foo(42)
assert_equal(Int(foo), 42)Implemented traitsโ
Required methodsโ
__int__โ
__int__(self: _Self) -> Int
Get the integral representation of the value.
Returns:
Int: The integral representation of the type.
Raises:
If the type does not have an integral representation.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!