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 Topological for bool {
13    fn accept_points(&self, _: &mut impl PointVisitor) {}
14}
15
16impl Tagged for bool {}
17
18impl Size for bool {
19    type Size = U1;
20}
21
22pub struct BoolNiche;
23
24impl Niche for BoolNiche {
25    type NeedsTag = typenum::B0;
26    type N = U1;
27    fn niche() -> GenericArray<u8, Self::N> {
28        GenericArray::from_array([2])
29    }
30}
31
32impl MaybeHasNiche for bool {
33    type MnArray = SomeNiche<BoolNiche>;
34}
35
36impl<I: ParseInput> Parse<I> for bool {
37    fn parse(input: I) -> crate::Result<Self> {
38        ParseInline::parse_as_inline(input)
39    }
40}
41
42impl<I: ParseInput> ParseInline<I> for bool {
43    fn parse_inline(input: &mut I) -> crate::Result<Self> {
44        match input.parse_chunk::<1>()? {
45            [0] => Ok(false),
46            [1] => Ok(true),
47            [_] => Err(Error::OutOfBounds),
48        }
49    }
50}
51
52impl Object for bool {}
53impl Inline for bool {}
54impl ReflessObject for bool {}
55impl ReflessInline for bool {}