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