Curriculum Collections & iteration Vectors
Vectors
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.
Exercises
9 ready
01
pick one
TypeScript's number[] describes a resizable owned array of
02
pick one
Build a vector containing [1, 2, 3]. Pick the idiomatic
03
pick one
A function reads xs.something(5) on a Vec<i32> that might
04
fill blanks
Fill the method that appends 42 to the end of xs in place.
05
fill blanks
Fill the parameter type. The function reads from a sequence of
06
write a program
Write build_vec() -> Vec<i32> that creates an empty vector
07
write a program
Write product(xs: &[i32]) -> i32 that returns the product of
08
write a program
Translate the TypeScript array code. Start with vec![1, 2, 3],
09
write a program
This program fails with `error[E0382]: borrow of moved value: