cheat/
cheat.rs

1use orn::*;
2
3/// Often, the type of iterator is conditional to some input value. Typically,
4/// to unify the return type, one would need to implement a custom iterator, but
5/// here `orn` types are used instead.
6pub fn unify_divergent(array_or_range: bool) -> impl Iterator<Item = u8> {
7    if array_or_range {
8        Or2::T0([1u8, 2u8])
9    } else {
10        Or2::T1(0u8..10u8)
11    }
12    .into_iter()
13    // The item of the `Or` iterator is `Or<u8, u8>`. `Or::into` collapses an `Or` value into a
14    // specified type.
15    .map(Or2::into)
16}
17
18/// Using the `tn` methods, items of an `Or` value can be retrieved.
19pub fn retrieve_dynamically(input: Or3<u8, usize, [char; 1]>) {
20    let _a: Option<u8> = input.t0();
21    let _b: Option<usize> = input.t1();
22    let _c: Option<[char; 1]> = input.t2();
23}
24
25/// Using the `At<I>` trait, items of an `Or` value can be retrieved
26/// generically.
27pub fn retrieve_statically(input: Or4<char, bool, isize, u32>) {
28    let _a: Option<char> = At::<0>::at(input);
29    let _b: Option<bool> = At::<1>::at(input);
30    let _c: Option<isize> = At::<2>::at(input);
31    let _d: Option<u32> = At::<3>::at(input);
32}
33
34fn main() {}