OxL Reference

method i16.try

x.try<U>(): checked conversion to the numeric type U (§3.1).

Example:

oxl✓ checked in CI
fn main() io {
  let small: i16 = 200
  let other: i16 = 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 | OutOfRange

Complexity. 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:912

See also