Skip to content

Commit 9abc56d

Browse files
committed
Raw const's now private. Added Id::is_standard() -> bool
1 parent 89572ca commit 9abc56d

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

embedded-can/src/id.rs

+18-13
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl StandardId {
1313
pub const MAX: Self = Self(Self::MAX_RAW);
1414

1515
/// Raw CAN ID `0x7FF`, the lowest priority.
16-
pub const MAX_RAW: u16 = 0x7FF;
16+
const MAX_RAW: u16 = 0x7FF;
1717

1818
/// Tries to create a `StandardId` from a raw 16-bit integer.
1919
///
@@ -59,7 +59,7 @@ impl ExtendedId {
5959
pub const MAX: Self = Self(Self::MAX_RAW);
6060

6161
/// Raw CAN ID `0x1FFFFFFF`, the lowest priority.
62-
pub const MAX_RAW: u32 = 0x1FFF_FFFF;
62+
const MAX_RAW: u32 = 0x1FFF_FFFF;
6363

6464
/// Tries to create a `ExtendedId` from a raw 32-bit integer.
6565
///
@@ -112,16 +112,20 @@ pub enum Id {
112112

113113
impl Id {
114114
/// 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> {
116116
Some(Id::from(StandardId::new(raw)?))
117117
}
118118

119119
/// 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> {
121121
Some(Id::from(ExtendedId::new(raw)?))
122122
}
123123

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.
125129
pub fn is_extended(&self) -> bool {
126130
matches!(self, Id::Extended(_))
127131
}
@@ -185,10 +189,7 @@ mod tests {
185189

186190
#[test]
187191
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));
192193
}
193194

194195
#[test]
@@ -242,15 +243,19 @@ mod tests {
242243

243244
#[test]
244245
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());
246249
match id {
247-
Some(Id::Standard(id)) => assert_eq!(StandardId::MAX, id),
250+
Id::Standard(id) => assert_eq!(StandardId::MAX, id),
248251
_ => assert!(false),
249252
}
250253

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());
252257
match id {
253-
Some(Id::Extended(id)) => assert_eq!(ExtendedId::MAX, id),
258+
Id::Extended(id) => assert_eq!(ExtendedId::MAX, id),
254259
_ => assert!(false),
255260
}
256261
}

0 commit comments

Comments
 (0)