exhaust 0.1.2

Trait and derive macro for working with all possible values of a type (exhaustive enumeration).
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
use core::iter;

use crate::Exhaust;

impl<T: Exhaust> Exhaust for Option<T> {
    #![allow(clippy::type_complexity)] // TODO: use macro to generate an opaque iter
    type Iter =
        iter::Chain<iter::Once<Option<T>>, iter::Map<<T as Exhaust>::Iter, fn(T) -> Option<T>>>;

    fn exhaust() -> Self::Iter {
        iter::once(None).chain(T::exhaust().map(Some as _))
    }
}