Exploring Basic Data Types in Rust
Introduction to Basic Data Types in Rust
In Rust, we have various data types that represent numbers, truth values, characters, and more. In this lesson, we will focus on i32, f32, bool, char, and String.
The i32 data type represents 32-bit integers. The maximum value an i32 can store is 2147483647, or , and the minimum is -2147483648, or . Here's an example of i32:
Next, we have the f32 data type in Rust, used for floating-point numbers — that is, numbers with decimal points. It can contain up to 7 decimal digits:
Beyond numbers, we have the bool data type, which can hold either true or false. This type is commonly used in logical expressions and decision making:
We also have the char data type. This type is used to represent single Unicode character. char variables must be surrounded by single quotes (')
Exploring the String Data Type
Last but not least, we have String. String is used to store a sequence of char elements.
There are two types of Strings in Rust.
String literals are immutable and have a type of &str.
On the other hand, a String is by default immutable, but can be made mutable using the mut keyword.
Lesson Recap
