OxL Справочник OxL
РусскийEnglish

method u8.try

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

Example:

oxl✓ проверяется в CI
fn main() io {
  let small: u8 = 100
  let other: u8 = 200
  match small.try<i8>() {
    i8 v => print("ok {v}")
    OutOfRange _ => print("out of range")
  }
  match other.try<i8>() {
    i8 v => print("ok {v}")
    OutOfRange _ => print("out of range")
  }
}
Вывод
ok 100
out of range
pub(api) fn try<U>() -> U | OutOfRange

Сложность. O(1).

С версии. 1.0.0-beta

Возвращает

U

Ошибки

  • OutOfRange @error
  • `OutOfRange` when the value is outside the range of `U`.

Эффекты

не объявлены (чистая, пока тело не говорит иное)

Определено в: std/core/numbers.oxl:3214

См. также