Week 1 Review & Practice
Review the fundamentals of Rust and build a CLI tool to practice everything you've learned so far.
Learning Objectives
- Review variables, types, and functions
- Practice ownership and control flow
- Build a 'Basic Geometry Calculator' CLI tool
Week 1 Wrap-up
Congratulations on finishing your first week with Rust! You’ve navigated the most challenging part of the learning curve: understanding how Rust thinks about memory and safety.
What We’ve Covered
- Day 1: Installation and Cargo.
- Day 2: Immutability vs. Mutability and Shadowing.
- Day 3: Scalars (i32, char) and Compounds (Tuples, Arrays).
- Day 4: Functions, Statements vs. Expressions.
- Day 5: If/Else as expressions and Loop types.
- Day 6: The 3 Rules of Ownership.
Practice Project: Geometry CLI
Today, you’ll build a CLI tool that calculates the area of different shapes. This will practice variables, functions, control flow, and user input.
Step 1: Create the Project
|
|
Step 2: Getting User Input
To read from the terminal, we’ll use the standard library io.
|
|
Project Requirements
- Implement
calculate_rectangleandcalculate_circle. - Use functions that return values for the actual math.
- Handle invalid input (like letters instead of numbers) using
match(don’t worry about the details of match yet, just use the pattern in the example).
Self-Check Quiz
- Can I explain why
let x = 5; x = 6;fails? - Do I know when to use a Tuple vs. an Array?
- Can I identify an Expression vs. a Statement?
- Do I understand why
let s2 = s1might makes1unusable?
Summary
You’ve built a solid foundation. While Ownership might still feel a bit “mystical,” it will become second nature as we dive into Borrowing and References next week.
Next Steps
In Week 2, we solve the “Ownership problem” with Borrowing and References, learn about Slices, and start organizing data with Structs!
Quiz
Complete this quiz with a minimum score of 80% to mark Day 7 as complete.
Discussion
Have questions or want to discuss this lesson? Join the conversation below!