Skip to main content

object_rainbow/
decr_byte_niche.rs

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