Skip to main content

object_rainbow/impls/
ordering.rs

1use std::cmp::Ordering;
2
3use typenum::U1;
4
5use crate::*;
6
7impl ToOutput for Ordering {
8    fn to_output(&self, output: &mut impl Output) {
9        (*self as i8).to_output(output);
10    }
11}
12
13impl InlineOutput for Ordering {}
14impl Tagged for Ordering {}
15impl ListHashes for Ordering {}
16impl Topological for Ordering {}
17
18impl<I: ParseInput> Parse<I> for Ordering {
19    fn parse(input: I) -> crate::Result<Self> {
20        Self::parse_as_inline(input)
21    }
22}
23
24impl<I: ParseInput> ParseInline<I> for Ordering {
25    fn parse_inline(input: &mut I) -> crate::Result<Self> {
26        match input.parse_inline::<i8>()? {
27            -1 => Ok(Self::Less),
28            0 => Ok(Self::Equal),
29            1 => Ok(Self::Greater),
30            _ => Err(Error::OutOfBounds),
31        }
32    }
33}
34
35impl Size for Ordering {
36    type Size = U1;
37    const SIZE: usize = 1;
38}