Activity 21 - Confidence rating and mini-quiz

Name:



On your the last page of your packets there is a sheet of questions.

You do NOT have to answer them.

Instead, rate each question on how confident you would be if you had to answer it now

  • ๐Ÿ˜Š ๐Ÿคจ โ˜น๏ธ
  • 1-5
  • ๐Ÿ”ด ๐ŸŒ• ๐ŸŸข

Then pick THREE questions to answer and turn your sheet in.

(The list of questions will be available online after class.)

Self-quiz

You should be able to answer:

  1. When does Rust move vs copy data?

  2. Why can't you have &mut T and &T simultaneously?

  3. Why is &str usually better than String for parameters?

  4. What's the difference between .iter() and .iter_mut()?

  5. When should you use a HashMap instead of a Vec?

  6. What are the three ownership rules and two borrow-checker rules?

  7. What's the difference between stack and heap memory?

  8. When would you use &self vs &mut self vs self in a method?

  9. What does .collect() do and why does it need a type annotation?

  10. What's the difference between a struct and an enum?

  11. Why can't you index into a String with text[0]?

  12. What happens when you call .clone() on a Vec?

  13. Why does .get() on HashMap return an Option?

  14. What happens if you try to modify a Vec while iterating over it with .iter()?

  15. What's the purpose of the .entry().or_insert() pattern in HashMap?

  16. What's a tuple struct and when would you use one?



17. **Stack/Heap Diagram**

Draw a stack/heap diagram showing memory after this code executes:

#![allow(unused)]
fn main() {
let mut scores = vec![85, 92, 78];
let first = scores[0];
let scores_ref = &scores;
}


18. **Debugging:**

What's wrong with this code and how would you fix it?

fn process_data(data: Vec<i32>) {
    println!("Processing: {:?}", data);
}

fn main() {
    let numbers = vec![1, 2, 3];
    process_data(numbers);
    println!("Numbers: {:?}", numbers); 
}