01 · Fundamentals
- variables
- let / let mut / const
- shadowing
- primitive types
- tuples / arrays
End of the Rust Course
Congratulations: you have made it through the 4 modules of the Rust Course — from your very first variables and default immutability to ownership, borrowing, and implementing methods on structs. Below is a map of everything you have mastered and a three-step final challenge.
Reminder: Rust exercises are verified statically (keywords). To actually run the code, each exercise provides a Rust Playground button that copies the code and opens play.rust-lang.org.
Combine what you have learned about Rust by building three small logical components: a boolean checker, an in-place modification using pass-by-mutable-reference, and a struct that encapsulates a count value.
Write a function that accepts a 32-bit integer and returns true if it is even, false otherwise. Module 1 (operators) + Module 2 (functions).
Define the function is_even(n: i32) -> bool that returns a boolean value indicating if the passed number is even (n % 2 == 0).
Use the return type -> bool and the modulo operator (%). Example: n % 2 == 0
Solution available after 3 attempts
Write a function that receives a mutable reference to an integer and squares it directly in the original variable. Module 3 (pass-by-mutable-reference).
Define the function square_by_ref(n: &mut i32) that accepts a mutable reference to an integer and calculates its square in-place, dereferencing n to modify it.
Inside the function write *n = *n * *n; to access and modify the value pointed to by the reference.
Solution available after 3 attempts
Create a struct with private fields that provides public methods to initialize the value to 0, increment it, and read it. Module 4 (structs and methods).
Complete the implementation of Counter by defining pub fn new() -> Counter returning Counter with count at 0, pub fn increment(&mut self) incrementing count by 1, and pub fn get_count(&self) -> u32 returning count.
Use the pub keyword to make the methods accessible outside of the impl block.
Solution available after 3 attempts
A single page with all the essential syntax of modern Rust, ready to keep handy while you code.
Consistent practice is the best way to strengthen your skills. Open the Rust Playground to experiment freely with complex scenarios or to prepare your code snippets before testing them on a real compiler.