raw ID getter function

This commit is contained in:
Robin Mueller 2025-05-13 10:02:37 +02:00 committed by Robin Mueller
parent 21e547acd5
commit bd66331aa2
2 changed files with 22 additions and 0 deletions

View File

@ -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

View File

@ -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