spaces/discrete/
integers.rs1use crate::prelude::*;
2use std::fmt;
3
4#[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#[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#[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}