From 9db215fa274d9614dab2806dd865946ee4fa15aa 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 | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/embedded-can/CHANGELOG.md b/embedded-can/CHANGELOG.md index f8719d63..73139438 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` 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..b00c8f03 100644 --- a/embedded-can/src/id.rs +++ b/embedded-can/src/id.rs @@ -104,6 +104,17 @@ pub enum Id { Extended(ExtendedId), } +impl Id { + /// Returns the CAN Identifier as a raw 32-bit integer. + #[inline] + pub fn as_raw(&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