Skip to main content

object_rainbow/
ff.rs

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