sumtype 0.4.0

Generate zerocost anonymous sum types that implement common traits
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// `repeat().take()` matches the explicit `Take<Repeat<_>>` type named in the `sumtype!` call.
#![allow(clippy::manual_repeat_n)]
use sumtype::sumtype;

#[allow(unused)]
#[sumtype(sumtype::traits::Iterator)]
fn with_generics<'a, T>(t: &'a T, count: usize) -> sumtype!() {
    match count {
        0 => sumtype!(std::iter::empty(), std::iter::Empty<&'a T>),
        1 => sumtype!(std::iter::once(t), std::iter::Once<&'a T>),
        n => sumtype!(
            std::iter::repeat(t).take(n),
            std::iter::Take<std::iter::Repeat<&'a T>>
        ),
    }
}