From 9c7204813352b155dec069a15206c7658e685833 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 13 May 2025 10:02:37 +0200 Subject: [PATCH] raw ID getter function --- embedded-can/CHANGELOG.md | 4 ++++ embedded-can/src/id.rs | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/embedded-can/CHANGELOG.md b/embedded-can/CHANGELOG.md index f8719d63..84a11f7f 100644 --- a/embedded-can/CHANGELOG.md +++ b/embedded-can/CHANGELOG.md @@ -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 diff --git a/embedded-can/src/id.rs b/embedded-can/src/id.rs index b0d6d4d5..2f113b16 100644 --- a/embedded-can/src/id.rs +++ b/embedded-can/src/id.rs @@ -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 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