liveBook · Manning

Unicode escape

As explained in Learn Rust in a Month of Lunches

A Unicode escape is a string-literal notation that represents a Unicode character using a hexadecimal code point.

A Unicode escape represents a Unicode character inside a Rust string by placing its hexadecimal code point inside \u{}. section 2.10

Printing characters from code points

Convert characters such as Korean 행, H, 居, and Japanese い to hexadecimal u32 values, then print them again with escapes: println!("\u{D589}, \u{48}, \u{5C45}, \u{3044}").

fn main() {
    println!("{:X}", '행' as u32);                      #1
    println!("{:X}", 'H' as u32);
    println!("{:X}", '居' as u32);
    println!("{:X}", 'い' as u32);
 
    println!("\u{D589}, \u{48}, \u{5C45}, \u{3044}");   #2
}

Compare hexadecimal code-point output with the corresponding Unicode escapes in a focused Rust listing. section 2.10

How Learn Rust in a Month of Lunches covers it

How deep it goes
Defines the syntax and demonstrates conversion through u32, but does not develop Unicode encoding internals.
Examples
Shows 행, H, 居, and い as characters, hexadecimal values, and Unicode escapes.
What you can do after
Apply it via Rust string literals to print selected Unicode characters from hexadecimal code points.
How it connects
Connects string literals, character literals, hexadecimal numbers, u32 values, and println! formatting.

Also explained in

Compare how 2 books explain Unicode escape →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Rust in a Month of Lunches. The section links point to the parts of the book it draws on.