object_rainbow/impls/
bool.rs

1use generic_array::GenericArray;
2use typenum::U1;
3
4use crate::*;
5
6impl ToOutput for bool {
7    fn to_output(&self, output: &mut dyn Output) {
8        output.write(&[*self as _])
9    }
10}
11
12impl Size for bool {
13    type Size = U1;
14}
15
16pub struct BoolNiche;
17
18impl Niche for BoolNiche {
19    type NeedsTag = typenum::B0;
20    type N = U1;
21    fn niche() -> GenericArray<u8, Self::N> {
22        GenericArray::from_array([2])
23    }
24}
25
26impl MaybeHasNiche for bool {
27    type MnArray = SomeNiche<BoolNiche>;
28}
29
30impl<I: ParseInput> Parse<I> for bool {
31    fn parse(input: I) -> crate::Result<Self> {
32        ParseInline::parse_as_inline(input)
33    }
34}
35
36impl<I: ParseInput> ParseInline<I> for bool {
37    fn parse_inline(input: &mut I) -> crate::Result<Self> {
38        match input.parse_chunk::<1>()? {
39            [0] => Ok(false),
40            [1] => Ok(true),
41            [_] => Err(Error::OutOfBounds),
42        }
43    }
44}
45
46impl Topological for bool {}
47impl Tagged for bool {}
48impl Object for bool {}
49impl Inline for bool {}
50impl ReflessObject for bool {}
51impl ReflessInline for bool {}