6
6
use core:: fmt;
7
7
use core:: hash:: { Hash , Hasher } ;
8
8
use core:: num:: ParseIntError ;
9
+ use core:: ops:: Range ;
9
10
use core:: str:: FromStr ;
10
11
11
12
use serde:: de:: { Deserialize , Deserializer , Error , Visitor } ;
12
13
use serde:: ser:: { Serialize , Serializer } ;
13
14
15
+ /// Regular range
16
+ pub const REGULAR_RANGE : Range < u64 > = 1_000 ..10_000 ;
17
+ /// Replaceable range
18
+ pub const REPLACEABLE_RANGE : Range < u64 > = 10_000 ..20_000 ;
19
+ /// Ephemeral range
20
+ pub const EPHEMERAL_RANGE : Range < u64 > = 20_000 ..30_000 ;
21
+ /// Parameterized replaceable range
22
+ pub const PARAMETERIZED_REPLACEABLE_RANGE : Range < u64 > = 30_000 ..40_000 ;
23
+
14
24
/// Event [`Kind`]
15
25
#[ derive( Debug , Clone , Copy , Eq , PartialOrd , Ord ) ]
16
26
pub enum Kind {
@@ -96,11 +106,11 @@ pub enum Kind {
96
106
HttpAuth ,
97
107
/// Regular Events (must be between 1000 and <=9999)
98
108
Regular ( u16 ) ,
99
- /// Replacabe event (must be between 10000 and <20000)
109
+ /// Replaceable event (must be between 10000 and <20000)
100
110
Replaceable ( u16 ) ,
101
111
/// Ephemeral event (must be between 20000 and <30000)
102
112
Ephemeral ( u16 ) ,
103
- /// Parameterized Replacabe event (must be between 30000 and <40000)
113
+ /// Parameterized replaceable event (must be between 30000 and <40000)
104
114
ParameterizedReplaceable ( u16 ) ,
105
115
/// Custom
106
116
Custom ( u64 ) ,
@@ -116,6 +126,26 @@ impl Kind {
116
126
pub fn as_u64 ( & self ) -> u64 {
117
127
( * self ) . into ( )
118
128
}
129
+
130
+ /// Check if [`Kind`] is `Regular`
131
+ pub fn is_regular ( & self ) -> bool {
132
+ REGULAR_RANGE . contains ( & self . as_u64 ( ) )
133
+ }
134
+
135
+ /// Check if [`Kind`] is `Replaceable`
136
+ pub fn is_replaceable ( & self ) -> bool {
137
+ REPLACEABLE_RANGE . contains ( & self . as_u64 ( ) )
138
+ }
139
+
140
+ /// Check if [`Kind`] is `Ephemeral`
141
+ pub fn is_ephemeral ( & self ) -> bool {
142
+ EPHEMERAL_RANGE . contains ( & self . as_u64 ( ) )
143
+ }
144
+
145
+ /// Check if [`Kind`] is `Parameterized replaceable`
146
+ pub fn is_parameterized_replaceable ( & self ) -> bool {
147
+ PARAMETERIZED_REPLACEABLE_RANGE . contains ( & self . as_u64 ( ) )
148
+ }
119
149
}
120
150
121
151
impl fmt:: Display for Kind {
@@ -167,10 +197,12 @@ impl From<u64> for Kind {
167
197
30078 => Self :: ApplicationSpecificData ,
168
198
1063 => Self :: FileMetadata ,
169
199
27235 => Self :: HttpAuth ,
170
- x if ( 1_000 ..10_000 ) . contains ( & x) => Self :: Regular ( x as u16 ) ,
171
- x if ( 10_000 ..20_000 ) . contains ( & x) => Self :: Replaceable ( x as u16 ) ,
172
- x if ( 20_000 ..30_000 ) . contains ( & x) => Self :: Ephemeral ( x as u16 ) ,
173
- x if ( 30_000 ..40_000 ) . contains ( & x) => Self :: ParameterizedReplaceable ( x as u16 ) ,
200
+ x if ( REGULAR_RANGE ) . contains ( & x) => Self :: Regular ( x as u16 ) ,
201
+ x if ( REPLACEABLE_RANGE ) . contains ( & x) => Self :: Replaceable ( x as u16 ) ,
202
+ x if ( EPHEMERAL_RANGE ) . contains ( & x) => Self :: Ephemeral ( x as u16 ) ,
203
+ x if ( PARAMETERIZED_REPLACEABLE_RANGE ) . contains ( & x) => {
204
+ Self :: ParameterizedReplaceable ( x as u16 )
205
+ }
174
206
x => Self :: Custom ( x) ,
175
207
}
176
208
}
0 commit comments