Skip to content

Commit 89572ca

Browse files
committed
Removed Id::as_raw() and cleaned up a little.
1 parent 1646f05 commit 89572ca

File tree

1 file changed

+7
-31
lines changed

1 file changed

+7
-31
lines changed

embedded-can/src/id.rs

+7-31
Original file line numberDiff line numberDiff line change
@@ -113,31 +113,17 @@ pub enum Id {
113113
impl Id {
114114
/// Creates a CAN identifier as a standard ID.
115115
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)?))
118117
}
119118

120119
/// Creates a CAN identifier as an extended ID.
121120
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)?))
133122
}
134123

135124
/// Determines if the value is an extended identifier.
136125
pub fn is_extended(&self) -> bool {
137-
match self {
138-
Id::Extended(_) => true,
139-
_ => false
140-
}
126+
matches!(self, Id::Extended(_))
141127
}
142128
}
143129

@@ -271,20 +257,10 @@ mod tests {
271257

272258
#[test]
273259
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());
285262

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());
289265
}
290266
}

0 commit comments

Comments
 (0)