docs

你正在阅读 v0.1.0 的文档。Nabi 0.1.0 已不再提供支持。 最新版本:v0.1.3 →

本页尚未翻译,以下为英文原文。

#E0053: invalid cast

as converts between numbers, bool and char, and a payload-less enum to an integer; other conversions are methods. Only u8 casts to char (use char::from_u32(n) for wider values), and nothing casts to bool (compare: n != 0). Use the conversion method the message suggests.

nabi
let n = 98u32;
let c = n as char;
error[E0053]: only `u8` can be cast as `char`, not `u32`; use `char::from_u32(n)` (`char | none`) for a wider value
  --> main.nabi:2:9
   |
 2 | let c = n as char;
   |         ^^^^^^^^^

Convert with char::from_u32, which gives none for values that are not characters:

nabi
let n = 98u32;
let c = char::from_u32(n) ?? '?';
println(f"{c}");
b

Related: E0040 mismatched types

Found a mistake? Edit this page on GitHub. Last updated