zebra
zebra copied to clipboard
Add new type similar to `AtLeastOne` to enforce min/max size constraints and use it instead of `Vec`s in `AdjustedDifficulty`
Motivation
There's repetitive code around taking a constant number of items from an iterator to collect into a Vec
, and there are max size constraints that aren't currently enforced in AdjustedDifficulty
methods.
It would be easier to maintain and verify correctness if we had a struct that handled this logic instead.
Design
Create a new type similar to AtLeastOne
with a const generic for max size, which:
- Calls
take()
to ensure the max size is enforced, and
Either:
- Uses
AtLeastOne
as the inner type to check that there's at least one element, or - Accepts another const generic for min size and returns an error if there are fewer items in the iterator than the
min
size (optional)
Currently the minimum length for this use case is 1, so using AtLeastOne
as the inner type would suffice.