Use `as` to explicitly convert a value to another primitive type. For example, `my_number as char` asks Rust to treat a number as a character. The source type matters: an ordinary `let my_number = 100` is inferred as `i32`, which cannot be cast directly to `char`. section 1.3
error[E0604]: only u8 can be cast as char, not i32
--> src\main.rs:3:20
|
3 | println!("{}", my_number as char);
| ^^^^^^^^^^^^^^^^^
The compiler points to the cast and explains the fixable problem: only `u8`, not `i32`, can be cast to `char`. section 1.3
fn main() {
let my_number = 100;
println!("{}", my_number as u8 as char);
}
Convert to `u8` first, then to `char`: `my_number as u8 as char`. Alternatively, declare `my_number: u8` from the start. section 1.3


