expression
Validate Unicode scalar values before construction
Rust char holds a Unicode scalar value, not every possible u32. Use the checked constructor to reject surrogate code points and values outside the Unicode range. Expected stdout (not executed): Some('A') None Common mistake: Assuming all 32-bit integers can be reinterpreted as char.
Formal Syntax & Structure
rust syntaxrust
char::from_u32(code)Working Example
Example Snippetrust
#![deny(unsafe_op_in_unsafe_fn)]fn main() { println!("{:?} {:?}", char::from_u32(65), char::from_u32(0xD800));}