object_rainbow/impls/
bool.rs1use typenum::{U1, U2};
2
3use crate::{incr_byte_niche::IncrByteNiche, *};
4
5impl ToOutput for bool {
6 fn to_output(&self, output: &mut impl Output) {
7 if output.is_real() {
8 output.write(&[*self as _])
9 }
10 }
11}
12
13impl InlineOutput for bool {}
14
15impl Size for bool {
16 type Size = U1;
17}
18
19impl MaybeHasNiche for bool {
20 type MnArray = SomeNiche<IncrByteNiche<U2>>;
21}
22
23impl<I: ParseInput> Parse<I> for bool {
24 fn parse(input: I) -> crate::Result<Self> {
25 ParseInline::parse_as_inline(input)
26 }
27}
28
29impl<I: ParseInput> ParseInline<I> for bool {
30 fn parse_inline(input: &mut I) -> crate::Result<Self> {
31 match input.parse_chunk::<1>()? {
32 [0] => Ok(false),
33 [1] => Ok(true),
34 [_] => Err(Error::OutOfBounds),
35 }
36 }
37}
38
39impl Tagged for bool {}
40impl ListHashes for bool {}
41impl Topological for bool {}
42
43#[test]
44fn none_is_2() {
45 assert_eq!(None::<bool>.vec(), [2]);
46}
47
48#[test]
49fn none_none_is_2() {
50 assert_eq!(None::<Option<bool>>.vec(), [3]);
51}