Skip to main content

CanId

Struct CanId 

Source
pub struct CanId { /* private fields */ }
Expand description

A CAN arbitration identifier.

CAN comes in two identifier widths: the original standard 11-bit form and the extended 29-bit form that higher-layer protocols such as J1939 use to pack a priority, a parameter group, and addresses into the ID itself. This type holds either, always masked to its width.

§Examples

use pamoja_can::CanId;

let std = CanId::standard(0x123);
assert!(!std.is_extended());
assert_eq!(std.raw(), 0x123);

// Values wider than the identifier are masked to fit.
assert_eq!(CanId::standard(0xFFFF).raw(), 0x7FF);

Implementations§

Source§

impl CanId

Source

pub const STANDARD_MASK: u32 = 0x7FF

The mask of a standard 11-bit identifier.

Source

pub const EXTENDED_MASK: u32 = 0x1FFF_FFFF

The mask of an extended 29-bit identifier.

Source

pub fn standard(raw: u16) -> CanId

Creates a standard 11-bit identifier, masking the value to fit.

§Arguments
  • raw - the identifier value; bits above the low 11 are dropped.
§Returns

The identifier.

Source

pub fn extended(raw: u32) -> CanId

Creates an extended 29-bit identifier, masking the value to fit.

§Arguments
  • raw - the identifier value; bits above the low 29 are dropped.
§Returns

The identifier.

Source

pub fn raw(&self) -> u32

Returns the identifier value.

§Returns

The raw bits, already masked to the identifier’s width.

Source

pub fn is_extended(&self) -> bool

Reports whether this is an extended 29-bit identifier.

§Returns

true for an extended identifier, false for a standard one.

Trait Implementations§

Source§

impl Clone for CanId

Source§

fn clone(&self) -> CanId

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for CanId

Source§

impl Debug for CanId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for CanId

Source§

impl PartialEq for CanId

Source§

fn eq(&self, other: &CanId) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for CanId

Auto Trait Implementations§

§

impl Freeze for CanId

§

impl RefUnwindSafe for CanId

§

impl Send for CanId

§

impl Sync for CanId

§

impl Unpin for CanId

§

impl UnsafeUnpin for CanId

§

impl UnwindSafe for CanId

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.