Char Type in Rust

Pascal Precht
InstructorPascal Precht
Share this video with your friends

Social Share Links

Send Tweet

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

Instructor: [00:00] 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.

[00:22] 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.

[00:38] 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.