Ben Chuanlong Du's Blog

It is never too late to learn.

Char in Rust

In [ ]:
:timing
:sccache 1

Character

Rust supports unicode characters. Notice that emojis are single unicode characters.

In [6]:
let c1 = 'a';
c1
Out[6]:
'a'
In [2]:
let c2 = '\u{1f604}';
c2
Out[2]:
'😄'

char::from_u32

In [5]:
'Z' as u32
Out[5]:
90
In [2]:
char::from_u32(90)
Out[2]:
Some('Z')
In [4]:
let c = char::from_u32(0x2764);
c
Out[4]:
Some('❤')

char::from_digit

In [6]:
char::from_digit(9, 10)
Out[6]:
Some('9')

char::to_uppercase

char::to_uppercase returns an interator instead of a char!

In [7]:
'a'.to_uppercase()
Out[7]:
ToUppercase(One('A'))
In [8]:
'a'.to_uppercase().next()
Out[8]:
Some('A')
In [9]:
'a'.to_uppercase().next().unwrap()
Out[9]:
'A'
In [ ]:

Comments