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:
- When does Rust move vs copy data?
- Why can't you have
&mut Tand&Tsimultaneously?
- Why is
&strusually better thanStringfor parameters?
- What's the difference between
.iter()and.iter_mut()?
- When should you use a HashMap instead of a Vec?
- What are the three ownership rules and two borrow-checker rules?
- What's the difference between stack and heap memory?
- When would you use
&selfvs&mut selfvsselfin a method?
- What does
.collect()do and why does it need a type annotation?
- What's the difference between a struct and an enum?
- Why can't you index into a String with
text[0]?
- What happens when you call
.clone()on a Vec?
- Why does
.get()on HashMap return anOption?
- What happens if you try to modify a Vec while iterating over it with
.iter()?
- What's the purpose of the
.entry().or_insert()pattern in HashMap?
- 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); }