spaces/discrete/
integers.rs

1use crate::prelude::*;
2use std::fmt;
3
4/// Type representing the set of 64-bit integers.
5#[derive(Debug, Clone, Copy)]
6#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
7pub struct Integers;
8
9impl Space for Integers {
10    const DIM: usize = 1;
11
12    type Value = i64;
13
14    fn card(&self) -> Card { Card::Infinite }
15
16    fn contains(&self, _: &i64) -> bool { true }
17}
18
19impl OrderedSpace for Integers {}
20
21impl_union_intersect!(Integers, Integers);
22
23impl fmt::Display for Integers {
24    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
25        write!(f, "\u{2124}")
26    }
27}
28
29/// Type representing the set of non-zero 64-bit integers.
30#[derive(Debug, Clone, Copy)]
31#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
32pub struct NonZeroIntegers;
33
34impl Space for NonZeroIntegers {
35    const DIM: usize = 1;
36
37    type Value = i64;
38
39    fn card(&self) -> Card { Card::Infinite }
40
41    fn contains(&self, val: &i64) -> bool { *val != 0 }
42}
43
44impl OrderedSpace for NonZeroIntegers {}
45
46impl_union_intersect!(NonZeroIntegers, NonZeroIntegers);
47
48impl fmt::Display for NonZeroIntegers {
49    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
50        write!(f, "\u{2124}(!=0)")
51    }
52}
53
54/// Type representing the set of unsigned 64-bit integers.
55#[derive(Debug, Clone, Copy)]
56#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
57pub struct NonNegativeIntegers;
58
59impl Space for NonNegativeIntegers {
60    const DIM: usize = 1;
61
62    type Value = i64;
63
64    fn card(&self) -> Card { Card::Infinite }
65
66    fn contains(&self, _: &i64) -> bool { true }
67}
68
69impl OrderedSpace for NonNegativeIntegers {
70    fn min(&self) -> Option<i64> { Some(0) }
71}
72
73impl_union_intersect!(NonNegativeIntegers, NonNegativeIntegers);
74
75impl fmt::Display for NonNegativeIntegers {
76    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
77        write!(f, "\u{2124}(≥0)")
78    }
79}