logo
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use std::cmp::Ordering;

use super::*;

impl<T> From<T> for IntegerOnly
where
    T: Into<usize>,
{
    fn from(kind: T) -> Self {
        Self::Number(kind.into())
    }
}

impl Display for IntegerOnly {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Number(s) => write!(f, "{}", s),
            Self::Arbitrary(s) => write!(f, "[{}]", s),
        }
    }
}

impl PartialEq<usize> for IntegerOnly {
    fn eq(&self, other: &usize) -> bool {
        match self {
            Self::Number(s) => s.eq(other),
            Self::Arbitrary(_) => false,
        }
    }
}

impl PartialOrd<usize> for IntegerOnly {
    fn partial_cmp(&self, other: &usize) -> Option<Ordering> {
        match self {
            Self::Number(s) => s.partial_cmp(other),
            Self::Arbitrary(_) => None,
        }
    }
}