method i8.try
x.try<U>(): checked conversion to the numeric type U (§3.1).
Example:
fn main() io {
let small: i8 = 100
let other: i8 = -1
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 100 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:1255