Introduction to Basic Data Types in Rust
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.

Rust
let welcome1 = "Hello World!"; // Creates a string literal
println!("{}", welcome1); // This will print: Hello World!

On the other hand, a String is by default immutable, but can be made mutable using the mut keyword.

Rust
let mut welcome2 = String::from("Welcome to Rust!"); // Creates a new String
println!("{}", welcome2); // This will print: Welcome to Rust!

welcome2 = String::from("Hello Rust World!"); // Changing the value of welcome2
println!("{}", welcome2); // This will print: Hello Rust World!
Lesson Recap

Excellent! You've just explored the basic data types in Rust. You can now handle i32 and f32 for numerical operations, bool for decision-making, char to manage characters, and String to work with textual data.

That's a significant amount of new knowledge! Let's consolidate it through practice. The upcoming exercises are designed to help you apply these concepts. Brace yourself, and get ready to dive deeper into the world of Rust!

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal