Why can't I cast a `u32` to `char`?

2019-02-16 19:19发布

问题:

I'm trying to learn Rust and I got caught up thinking about how chars are 4 bytes wide. I can cast a char to a u32 and it works out (they are both 4 bytes wide), however, when I cast from a u32 to a char, Rust complains:

fn main() {
    let pizza_hex: u32 = 0x1f355;
    let pizza: char = '              
                            
标签: rust