@@ -113,31 +113,17 @@ pub enum Id {
113
113
impl Id {
114
114
/// Creates a CAN identifier as a standard ID.
115
115
pub fn new_standard_id ( raw : u16 ) -> Option < Self > {
116
- let id = StandardId :: new ( raw) ?;
117
- Some ( Id :: Standard ( id) )
116
+ Some ( Id :: from ( StandardId :: new ( raw) ?) )
118
117
}
119
118
120
119
/// Creates a CAN identifier as an extended ID.
121
120
pub fn new_extended_id ( raw : u32 ) -> Option < Self > {
122
- let id = ExtendedId :: new ( raw) ?;
123
- Some ( Id :: Extended ( id) )
124
- }
125
-
126
- /// Returns this CAN Identifier as a raw 32-bit integer, regardless of whether it's
127
- /// a standard or extended identifier.
128
- pub fn as_raw ( & self ) -> u32 {
129
- match self {
130
- Id :: Standard ( id) => id. as_raw ( ) as u32 ,
131
- Id :: Extended ( id) => id. as_raw ( ) ,
132
- }
121
+ Some ( Id :: from ( ExtendedId :: new ( raw) ?) )
133
122
}
134
123
135
124
/// Determines if the value is an extended identifier.
136
125
pub fn is_extended ( & self ) -> bool {
137
- match self {
138
- Id :: Extended ( _) => true ,
139
- _ => false
140
- }
126
+ matches ! ( self , Id :: Extended ( _) )
141
127
}
142
128
}
143
129
@@ -271,20 +257,10 @@ mod tests {
271
257
272
258
#[ test]
273
259
fn id_raw ( ) {
274
- const RAW_ID : u32 = StandardId :: MAX_RAW as u32 ;
275
-
276
- let id = StandardId :: new ( RAW_ID as u16 ) . unwrap ( ) ;
277
- assert_eq ! ( RAW_ID as u16 , id. as_raw( ) ) ;
278
-
279
- let id = Id :: from ( id) ;
280
- assert ! ( !id. is_extended( ) ) ;
281
- assert_eq ! ( RAW_ID , id. as_raw( ) ) ;
282
-
283
- let id = ExtendedId :: new ( RAW_ID ) . unwrap ( ) ;
284
- assert_eq ! ( RAW_ID , id. as_raw( ) ) ;
260
+ let id = StandardId :: new ( StandardId :: MAX_RAW ) . unwrap ( ) ;
261
+ assert_eq ! ( StandardId :: MAX_RAW , id. as_raw( ) ) ;
285
262
286
- let id = Id :: from ( id) ;
287
- assert ! ( id. is_extended( ) ) ;
288
- assert_eq ! ( RAW_ID , id. as_raw( ) ) ;
263
+ let id = ExtendedId :: new ( ExtendedId :: MAX_RAW ) . unwrap ( ) ;
264
+ assert_eq ! ( ExtendedId :: MAX_RAW , id. as_raw( ) ) ;
289
265
}
290
266
}
0 commit comments