@@ -103,31 +103,17 @@ pub enum Id {
103
103
impl Id {
104
104
/// Creates a CAN identifier as a standard ID.
105
105
pub fn new_standard_id ( raw : u16 ) -> Option < Self > {
106
- let id = StandardId :: new ( raw) ?;
107
- Some ( Id :: Standard ( id) )
106
+ Some ( Id :: from ( StandardId :: new ( raw) ?) )
108
107
}
109
108
110
109
/// Creates a CAN identifier as an extended ID.
111
110
pub fn new_extended_id ( raw : u32 ) -> Option < Self > {
112
- let id = ExtendedId :: new ( raw) ?;
113
- Some ( Id :: Extended ( id) )
114
- }
115
-
116
- /// Returns this CAN Identifier as a raw 32-bit integer, regardless of whether it's
117
- /// a standard or extended identifier.
118
- pub fn as_raw ( & self ) -> u32 {
119
- match self {
120
- Id :: Standard ( id) => id. as_raw ( ) as u32 ,
121
- Id :: Extended ( id) => id. as_raw ( ) ,
122
- }
111
+ Some ( Id :: from ( ExtendedId :: new ( raw) ?) )
123
112
}
124
113
125
114
/// Determines if the value is an extended identifier.
126
115
pub fn is_extended ( & self ) -> bool {
127
- match self {
128
- Id :: Extended ( _) => true ,
129
- _ => false
130
- }
116
+ matches ! ( self , Id :: Extended ( _) )
131
117
}
132
118
}
133
119
@@ -261,20 +247,10 @@ mod tests {
261
247
262
248
#[ test]
263
249
fn id_raw ( ) {
264
- const RAW_ID : u32 = StandardId :: MAX_RAW as u32 ;
265
-
266
- let id = StandardId :: new ( RAW_ID as u16 ) . unwrap ( ) ;
267
- assert_eq ! ( RAW_ID as u16 , id. as_raw( ) ) ;
268
-
269
- let id = Id :: from ( id) ;
270
- assert ! ( !id. is_extended( ) ) ;
271
- assert_eq ! ( RAW_ID , id. as_raw( ) ) ;
272
-
273
- let id = ExtendedId :: new ( RAW_ID ) . unwrap ( ) ;
274
- assert_eq ! ( RAW_ID , id. as_raw( ) ) ;
250
+ let id = StandardId :: new ( StandardId :: MAX_RAW ) . unwrap ( ) ;
251
+ assert_eq ! ( StandardId :: MAX_RAW , id. as_raw( ) ) ;
275
252
276
- let id = Id :: from ( id) ;
277
- assert ! ( id. is_extended( ) ) ;
278
- assert_eq ! ( RAW_ID , id. as_raw( ) ) ;
253
+ let id = ExtendedId :: new ( ExtendedId :: MAX_RAW ) . unwrap ( ) ;
254
+ assert_eq ! ( ExtendedId :: MAX_RAW , id. as_raw( ) ) ;
279
255
}
280
256
}
0 commit comments