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_vec
andvec1
take 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
pop
should succeed even when there is a single item is different from what these crates implement. We required it since it forcespop
to take ownership ofself
. Consuming methods are quite unique to Rust so this can lead to an interesting discussion on how to (safely) implementpop
in another language.