1#[derive(Debug, PartialOrd, PartialEq, Clone, Copy)]
14pub enum Bound<T> {
17 Included(T),
19 Excluded(T),
21}
22
23impl<T> Bound<T> {
25 pub fn value(&self) -> &T {
39 match self {
40 Bound::Included(value) => value,
41 Bound::Excluded(value) => value,
42 }
43 }
44}
45
46#[cfg(test)]
47mod tests {
48 use super::Bound;
49
50 #[test]
51 fn test_included() {
52 let bound = Bound::Included(5);
53 assert_eq!(bound, Bound::Included(5));
54 if let Bound::Included(value) = bound {
55 assert_eq!(value, 5);
56 } else {
57 panic!("Expected Bound::Included");
58 }
59 }
60
61 #[test]
62 fn test_excluded() {
63 let bound = Bound::Excluded(10);
64 assert_eq!(bound, Bound::Excluded(10));
65 if let Bound::Excluded(value) = bound {
66 assert_eq!(value, 10);
67 } else {
68 panic!("Expected Bound::Excluded");
69 }
70 }
71
72 #[test]
73 fn test_value_included() {
74 let bound = Bound::Included(15);
75 assert_eq!(bound.value(), &15);
76 }
77
78 #[test]
79 fn test_value_excluded() {
80 let bound = Bound::Excluded(20);
81 assert_eq!(bound.value(), &20);
82 }
83
84 #[test]
85 fn test_partial_eq() {
86 let bound1 = Bound::Included(25);
87 let bound2 = Bound::Included(25);
88 assert_eq!(bound1, bound2);
89
90 let bound3 = Bound::Excluded(30);
91 let bound4 = Bound::Excluded(30);
92 assert_eq!(bound3, bound4);
93
94 let bound5 = Bound::Included(35);
95 let bound6 = Bound::Excluded(35);
96 assert_ne!(bound5, bound6);
97 }
98
99 #[test]
100 fn test_partial_ord() {
101 let bound1 = Bound::Included(5);
102 let bound2 = Bound::Included(10);
103 assert!(bound1 < bound2);
104
105 let bound3 = Bound::Excluded(15);
106 let bound4 = Bound::Excluded(20);
107 assert!(bound3 < bound4);
108
109 let bound5 = Bound::Included(25);
110 let bound6 = Bound::Excluded(25);
111 assert!(bound5 < bound6);
112 }
113}