object_rainbow/
incr_byte_niche.rs1use std::ops::Add;
2
3use typenum::{B0, B1, IsLess, ToInt, U1, U255, U256};
4
5use crate::*;
6
7pub struct IncrByteNiche<K>(K);
8
9pub trait NextNiche {
10 type NextNiche;
11}
12
13pub trait WrapNext {
14 type Wrap<J>;
15}
16
17impl WrapNext for B1 {
18 type Wrap<J> = SomeNiche<IncrByteNiche<J>>;
19}
20
21impl WrapNext for B0 {
22 type Wrap<J> = NoNiche<ZeroNoNiche<U1>>;
23}
24
25impl<K: IsLess<U256, Output = B1> + Add<B1, Output = J> + IsLess<U255, Output = B>, J, B: WrapNext>
26 NextNiche for K
27{
28 type NextNiche = B::Wrap<J>;
29}
30
31impl<K: ToInt<u8> + NextNiche> Niche for IncrByteNiche<K> {
32 type NeedsTag = typenum::B0;
33 type N = U1;
34 fn niche() -> GenericArray<u8, Self::N> {
35 GenericArray::from_array([K::INT])
36 }
37 type Next = K::NextNiche;
38}