Here's a fun smallish, intermediate level rust exercise: Implement an extension trait that allows you to call .skipping(n) on an iterator, and only yield every nth item, starting with the first one. (An extension trait is one that adds functionality to anything that already implements a existing trait, usually one in std).
It should pass the test below.
Here are some hints if you need help:
- For examples of how to implement Iterator combinators, see the documentation (especially the src link) for the std::iter::Take struct, and the Iterator::take() method (or any of the other iterator combinator methods.
- For examples of how to implement an extension trait, see the excellent byteorder crate (by Andrew Gallant, a.k.a. BurntSushi), and its
ReadBytesExt
andWriteBytesExt
traits, which let you read and write integers of different sizes