Skip to main content

object_rainbow/
ff.rs

1use typenum::{U1, U254};
2
3use crate::{decr_byte_niche::DecrByteNiche, *};
4
5#[derive(
6    Debug,
7    Clone,
8    Copy,
9    PartialEq,
10    Eq,
11    PartialOrd,
12    Ord,
13    ListHashes,
14    Topological,
15    ParseAsInline,
16    Default,
17)]
18pub struct Ff;
19
20impl ToOutput for Ff {
21    fn to_output(&self, output: &mut impl Output) {
22        0xffu8.to_output(output);
23    }
24}
25
26impl InlineOutput for Ff {}
27
28impl<I: ParseInput> ParseInline<I> for Ff {
29    fn parse_inline(input: &mut I) -> crate::Result<Self> {
30        if input.parse_inline::<u8>()? == 0xff {
31            Ok(Self)
32        } else {
33            Err(Error::OutOfBounds)
34        }
35    }
36}
37
38impl ByteOrd for Ff {
39    fn bytes_cmp(&self, Self: &Self) -> Ordering {
40        Ordering::Equal
41    }
42}
43
44impl MaybeHasNiche for Ff {
45    type MnArray = SomeNiche<DecrByteNiche<U254>>;
46}
47
48#[test]
49fn ff_option() {
50    assert_eq!(Some(Ff).vec(), [0xff]);
51    assert_eq!(None::<Ff>.vec(), [0xfe]);
52    assert_eq!(None::<Option<Ff>>.vec(), [0xfd]);
53    assert_eq!(None::<Option<Option<Ff>>>.vec(), [0xfc]);
54}
55
56impl Size for Ff {
57    type Size = U1;
58}
59
60impl Monostate for Ff {}
61
62pub type FfCollection<T> = crate::none_terminated::Nt<
63    crate::monostate_headers::MonostateHeaders<T, (Ff, crate::niche_cut::NicheCut)>,
64>;
65
66#[test]
67fn ff_collection() {
68    let mut stuff = FfCollection::<Vec<u8>>::default();
69    stuff.push(1);
70    stuff.push(2);
71    assert_eq!(stuff.vec(), [0xff, 0x01, 0xff, 0x02, 0xfe]);
72}