Skip to content

Commit 9a053e8

Browse files
committed
Removed Id::as_raw() and cleaned up a little.
1 parent 016d524 commit 9a053e8

File tree

1 file changed

+7
-31
lines changed

1 file changed

+7
-31
lines changed

Diff for: embedded-can/src/id.rs

+7-31
Original file line numberDiff line numberDiff line change
@@ -103,31 +103,17 @@ pub enum Id {
103103
impl Id {
104104
/// Creates a CAN identifier as a standard ID.
105105
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)?))
108107
}
109108

110109
/// Creates a CAN identifier as an extended ID.
111110
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)?))
123112
}
124113

125114
/// Determines if the value is an extended identifier.
126115
pub fn is_extended(&self) -> bool {
127-
match self {
128-
Id::Extended(_) => true,
129-
_ => false
130-
}
116+
matches!(self, Id::Extended(_))
131117
}
132118
}
133119

@@ -261,20 +247,10 @@ mod tests {
261247

262248
#[test]
263249
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());
275252

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());
279255
}
280256
}

0 commit comments

Comments
 (0)