Curriculum Collections & iteration Vectors exercise 3 · mcq
Vectors
A function reads xs.something(5) on a Vec<i32> that might
be SHORTER than 5 elements. Pick the access form that returns
Option<&i32> instead of panicking.
TypeScript reference
About this theme
Vec<T> is Rust's growable array. This theme teaches vec![], push, indexing, .get, ownership of elements, and passing vectors by value or slice. Planned exercises: 1. choose Vec<T>. 2. recognise vec![...]. 3. choose .get() for optional access. 4. fill push. 5. fill a slice parameter. 6. write a vector builder. 7. write a function that reads &[T]. 8. translate TS array code. 9. fix a move caused by iterating a vector by value.