Chooce video playback speed
speed:1

Char Type in Rust

InstructorPascal Precht

Share this video with your friends

Send Tweet

This lesson discusses the char type in Rust, which holds 32 bit unicode values.

This lesson is a Community Resource

A Community Resource means that it’s free to access for all. The instructor of this lesson requested it to be open to the public.

Instructor: A character type or a char is a single Unicode character as a 32-bit value. They're created using single quotes. Here we see a couple of examples. Char1 is a character, '1'. Char2 is a character, 'a'. We can use any character Unicode that we like. Even emojis work, as we can see here.

Some characters have special meanings, so they need to be escaped using a . Here we see a \ escaping a , or a \ escaping a single quote. The same goes for a new line, a carriage return, and so on and so forth.

To see that this is working, we can, for example, create a new command here and say println!("{:?}" , "some more text"). Then we can give it, for example, char4 and run the program. We'll see, it'll output a backslash plus some text.