Instructor Notes
-
This exercise is intended to replace the Health Statistics Exercise exercise from the original version.
-
The solution includes links to several existing crates. If you have time, it can be beneficial to review their source code. In particular,
non_empty_vecandvec1take different approaches of wrapping a regularVec. -
You can ask students who finish early to replace
pub struct NonEmptyVec<T> {
head: T,
tail: Vec<T>,
}
with
pub struct NonEmptyVec<T>(Vec<T>)
and fix the body of all the methods accordingly.
- Our requirements that
popshould succeed even when there is a single item is different from what these crates implement. We required it since it forcespopto take ownership ofself. Consuming methods are quite unique to Rust so this can lead to an interesting discussion on how to (safely) implementpopin another language.