typeover
rust curriculum

Curriculum Ownership & borrowing Shared borrowing exercise 3 · mcq-explain

Shared borrowing

Inside fn count(s: &String) -> usize, you want to return the String's length. Method calls on references AUTO-DEREFERENCE — pick the body that compiles.

Pick the correct explanation

About this theme

Borrowing is how Rust lets code inspect data without taking it. &T references are shared, read-only views whose owner remains somewhere else. Planned exercises: 1. choose &String over String for a read helper. 2. recognise call-site borrowing with &name. 3. choose dereference-free field or method access. 4. fill an & parameter. 5. fill an & argument. 6. write a read-only helper. 7. write a caller that keeps using the owner afterward. 8. translate a TS read helper. 9. fix a function that accidentally takes ownership.