@@ -13,7 +13,7 @@ impl StandardId {
13
13
pub const MAX : Self = Self ( Self :: MAX_RAW ) ;
14
14
15
15
/// Raw CAN ID `0x7FF`, the lowest priority.
16
- pub const MAX_RAW : u16 = 0x7FF ;
16
+ const MAX_RAW : u16 = 0x7FF ;
17
17
18
18
/// Tries to create a `StandardId` from a raw 16-bit integer.
19
19
///
@@ -59,7 +59,7 @@ impl ExtendedId {
59
59
pub const MAX : Self = Self ( Self :: MAX_RAW ) ;
60
60
61
61
/// Raw CAN ID `0x1FFFFFFF`, the lowest priority.
62
- pub const MAX_RAW : u32 = 0x1FFF_FFFF ;
62
+ const MAX_RAW : u32 = 0x1FFF_FFFF ;
63
63
64
64
/// Tries to create a `ExtendedId` from a raw 32-bit integer.
65
65
///
@@ -112,16 +112,20 @@ pub enum Id {
112
112
113
113
impl Id {
114
114
/// Creates a CAN identifier as a standard ID.
115
- pub fn new_standard_id ( raw : u16 ) -> Option < Self > {
115
+ pub fn new_standard ( raw : u16 ) -> Option < Self > {
116
116
Some ( Id :: from ( StandardId :: new ( raw) ?) )
117
117
}
118
118
119
119
/// Creates a CAN identifier as an extended ID.
120
- pub fn new_extended_id ( raw : u32 ) -> Option < Self > {
120
+ pub fn new_extended ( raw : u32 ) -> Option < Self > {
121
121
Some ( Id :: from ( ExtendedId :: new ( raw) ?) )
122
122
}
123
123
124
- /// Determines if the value is an extended identifier.
124
+ /// Determines if the value is a standard, 11-bit, identifier.
125
+ pub fn is_standard ( & self ) -> bool {
126
+ matches ! ( self , Id :: Standard ( _) )
127
+ }
128
+ /// Determines if the value is an extended, 29-bit, identifier.
125
129
pub fn is_extended ( & self ) -> bool {
126
130
matches ! ( self , Id :: Extended ( _) )
127
131
}
@@ -185,10 +189,7 @@ mod tests {
185
189
186
190
#[ test]
187
191
fn standard_id_new ( ) {
188
- assert_eq ! (
189
- StandardId :: new( StandardId :: MAX_RAW ) ,
190
- Some ( StandardId :: MAX )
191
- ) ;
192
+ assert_eq ! ( StandardId :: new( StandardId :: MAX_RAW ) , Some ( StandardId :: MAX ) ) ;
192
193
}
193
194
194
195
#[ test]
@@ -242,15 +243,19 @@ mod tests {
242
243
243
244
#[ test]
244
245
fn id_new ( ) {
245
- let id = Id :: new_standard_id ( StandardId :: MAX_RAW ) ;
246
+ let id = Id :: new_standard ( StandardId :: MAX_RAW ) . unwrap ( ) ;
247
+ assert ! ( id. is_standard( ) ) ;
248
+ assert ! ( !id. is_extended( ) ) ;
246
249
match id {
247
- Some ( Id :: Standard ( id) ) => assert_eq ! ( StandardId :: MAX , id) ,
250
+ Id :: Standard ( id) => assert_eq ! ( StandardId :: MAX , id) ,
248
251
_ => assert ! ( false ) ,
249
252
}
250
253
251
- let id = Id :: new_extended_id ( ExtendedId :: MAX_RAW ) ;
254
+ let id = Id :: new_extended ( ExtendedId :: MAX_RAW ) . unwrap ( ) ;
255
+ assert ! ( !id. is_standard( ) ) ;
256
+ assert ! ( id. is_extended( ) ) ;
252
257
match id {
253
- Some ( Id :: Extended ( id) ) => assert_eq ! ( ExtendedId :: MAX , id) ,
258
+ Id :: Extended ( id) => assert_eq ! ( ExtendedId :: MAX , id) ,
254
259
_ => assert ! ( false ) ,
255
260
}
256
261
}
0 commit comments