In Rust,
the character type
(char) represents a unicode character.
Literal values are written using single quotes ('):
let c1 = 'A';
let c2 = 'ô';
let c3 = '∉';
(c1, c2, c3)('A', 'ô', '∉')Some special characters (see Table 1) are inserted using the escape character (backslash):
('\t', '\n')('\t', '\n')The escape character is also used to insert ASCII, 8-bit or Unicode characters knowing their number:
('\x39', '\u{2208}')('9', '∈')The from() method permits to convert an integer into a character:
char::from(0x30u8)'0'Table 1:Character escapes
Escape | Number | Name | Description |
|---|---|---|---|
| 0x00 | NL, NUL or NULL | Null |
| 0x09 | HT | Tab |
| 0x0A | LF | Newline (a.k.a.: line feed) |
| 0x0D | CR | Carriage return |
| 0x5C | Backslash | |
| 0x27 | Single quote | |
| 0x22 | Double quote | |
| ASCII or 8-bit character code | ||
| 24-bit Unicode character code (up to 6 hex digits) |