#[repr(C)]pub enum CanId {
Standard(StandardId),
Extended(ExtendedId),
}
Expand description
A CAN ID, either standard (11 bit) or extended (29 bits).
Variants§
Implementations§
Source§impl CanId
impl CanId
Sourcepub const fn new(id: u32) -> Result<Self, InvalidId>
pub const fn new(id: u32) -> Result<Self, InvalidId>
Create a new CAN ID from a raw value.
If the value fits in a 11 bit standard CAN ID,
this function will return Self::Standard
.
a standard ID will be created.
Otherwise, if the value fits in a 29 bits extended CAN ID,
this function returns Self::Extended
.
If the value doesn’t fit in either, this function returns an error.
Sourcepub const fn new_standard(id: u16) -> Result<Self, InvalidId>
pub const fn new_standard(id: u16) -> Result<Self, InvalidId>
Create a new standard CAN ID from a raw value.
If the value doesn’t fit in a standard 11 bit CAN ID, this function returns an error.
Sourcepub const fn new_extended(id: u32) -> Result<Self, InvalidId>
pub const fn new_extended(id: u32) -> Result<Self, InvalidId>
Create a new extended CAN ID from a raw value.
If the value doesn’t fit in an extended 29 bit CAN ID, this function returns an error.
Sourcepub const fn as_standard(self) -> Option<StandardId>
pub const fn as_standard(self) -> Option<StandardId>
Get self
as a StandardId
, or None
if this is an extended ID.
Note: This function always returns None
if self
is an extended ID.
It doesn’t matter if the value would have fit in a StandardId
.
Use Self::to_standard()
if you want to try to convert extended IDs to standard IDs.
Sourcepub const fn as_extended(self) -> Option<ExtendedId>
pub const fn as_extended(self) -> Option<ExtendedId>
Get self
as an ExtendedId
, or None
if this is a standard ID.
Use Self::to_extended()
if you want to convert standard IDs to extended IDs.
Sourcepub const fn to_standard(self) -> Result<StandardId, InvalidId>
pub const fn to_standard(self) -> Result<StandardId, InvalidId>
Try to convert the ID to a standard ID.
Returns an error if the value doesn’t fit in a standard ID.
Sourcepub const fn to_extended(self) -> ExtendedId
pub const fn to_extended(self) -> ExtendedId
Convert the ID to an extended ID.