mirror of
https://github.com/rust-embedded/embedded-hal.git
synced 2026-03-13 17:37:41 +00:00
raw ID getter function
This commit is contained in:
parent
21e547acd5
commit
bd66331aa2
@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
- Added `core::error::Error` implementations for every custom `impl Error`
|
||||
- Increased MSRV to 1.81 due to `core::error::Error`
|
||||
|
||||
### Added
|
||||
|
||||
- `as_raw_unchecked` getter function for `Id`
|
||||
|
||||
## [v0.4.1] - 2022-09-28
|
||||
|
||||
### Removed
|
||||
|
||||
@ -104,6 +104,24 @@ pub enum Id {
|
||||
Extended(ExtendedId),
|
||||
}
|
||||
|
||||
impl Id {
|
||||
/// Returns the CAN Identifier as a raw 32-bit integer, ignoring the distinction between
|
||||
/// standard ID and extended ID.
|
||||
///
|
||||
/// This function ignores that a standard ID and an extended ID are different IDs, even
|
||||
/// if their numerical values are the same. It should only be used if the raw numerical value
|
||||
/// is required and the distinction between standard ID and extended ID is irrelevant.
|
||||
///
|
||||
/// In all other cases, it is recommended to de-structure the ID with a match statement.
|
||||
#[inline]
|
||||
pub const fn as_raw_unchecked(&self) -> u32 {
|
||||
match self {
|
||||
Id::Standard(id) => id.as_raw() as u32,
|
||||
Id::Extended(id) => id.as_raw(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Implement `Ord` according to the CAN arbitration rules
|
||||
///
|
||||
/// When performing arbitration, frames are looked at bit for bit starting
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user