method i64.try
x.try<U>(): checked conversion to the numeric type U (§3.1).
Example:
fn main() io {
let small: i64 = 200
let other: i64 = 300
match small.try<u8>() {
u8 v => print("ok {v}")
OutOfRange _ => print("out of range")
}
match other.try<u8>() {
u8 v => print("ok {v}")
OutOfRange _ => print("out of range")
}
}Output
ok 200 out of range
pub(api) fn try<U>() -> U | OutOfRangeComplexity. O(1).
Since. 1.0.0-beta
Returns
U
Errors
OutOfRange@error- `OutOfRange` when the value is outside the range of `U`.
Effects
none declared (pure unless the body says otherwise)
Defined in: std/core/numbers.oxl:226