Struct Id

Source
pub struct Id<P: IsProtocol>(/* private fields */);
Expand description

Represents a Controller Area Network (CAN) identifier of a specific protocol.

Implementations§

Source§

impl Id<Can2A>

Source

pub const fn id(self) -> u16

Returns the value of the identifier, which is truncated to 11-bits.

Source§

impl Id<Can2B>

Source

pub const fn id(self) -> u32

Returns the value of the identifier, which is truncated to 29-bits.

Source§

impl Id<J1939>

Source

pub const fn into_raw_parts(self) -> (u8, bool, bool, u8, u8, u8)

Decomposes the 29-bit J1939 identifier into its raw parts.

Returns a tuple containing the priority, reserved flag, data page flag, PDU format, PDU specific, and source address bits.

§Examples
let id_a = IdJ1939::from_hex("00FF00FF");

let (p, r, dp, pf, ps, sa) = id_a.into_raw_parts();
Source

pub fn from_raw_parts( priority: u8, reserved: bool, data_page: bool, pdu_format: u8, pdu_specific: u8, source_addr: u8, ) -> Result<Self, Error>

Constructs a 29-bit J1939 identifier from its raw parts.

§Arguments
  • priority: u8.
  • reserved: bool.
  • data_page: bool.
  • pdu_format: u8.
  • pdu_specific: u8.
  • source_addr: u8.
§Errors
  • If priority value is invalid
§Examples
let expected_id = IdJ1939::from_hex("00FF00FF");

let id_a = IdJ1939::from_raw_parts(0x0, false, false, 0xFF, 0x00, 0xFF);

assert_eq!(expected_id, id_a.unwrap());
Source

pub const fn priority(&self) -> u8

Returns the priority bits indicating the priority level.

0 = highest priority

Source

pub const fn reserved(&self) -> bool

Returns the reserved flag - 0 or 1

Source

pub const fn data_page(&self) -> bool

Returns the data page flag - 0 or 1

Source

pub const fn pdu_format(&self) -> u8

Returns the PDU format bits specifying the Protocol Data Unit format.

Source

pub const fn pdu_specific(&self) -> u8

Returns the PDU specific bits providing additional details about the PDU.

Source

pub fn source_address(&self) -> SourceAddr

Returns the source address bits identifying the source of the data.

Source§

impl Id<J1939>

Source

pub const fn pgn_bits(&self) -> u32

Computes the PGN bitfield value based on the 29-bit identifier fields.

§Returns

The combined PGN bitfield value.

Source

pub const fn pgn(&self) -> Pgn

Constructs and returns a Pgn struct based on the 29-bit identifier fields.

§Returns

A Pgn bitfield initialized with the 29-bit identifier fields.

Trait Implementations§

Source§

impl<P: Clone + IsProtocol> Clone for Id<P>

Source§

fn clone(&self) -> Id<P>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<P: Debug + IsProtocol> Debug for Id<P>

Source§

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

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

impl From<Id<Can2A>> for IdCan2B

Source§

fn from(value: IdCan2A) -> Self

Converts to this type from the input type.
Source§

impl<P: Ord + IsProtocol> Ord for Id<P>

Source§

fn cmp(&self, other: &Id<P>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<P: PartialEq + IsProtocol> PartialEq for Id<P>

Source§

fn eq(&self, other: &Id<P>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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<P: PartialOrd + IsProtocol> PartialOrd for Id<P>

Source§

fn partial_cmp(&self, other: &Id<P>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<P: Copy + IsProtocol> Copy for Id<P>

Source§

impl<P: Eq + IsProtocol> Eq for Id<P>

Source§

impl<P: IsProtocol> StructuralPartialEq for Id<P>

Auto Trait Implementations§

§

impl<P> Freeze for Id<P>
where P: Freeze,

§

impl<P> RefUnwindSafe for Id<P>
where P: RefUnwindSafe,

§

impl<P> Send for Id<P>
where P: Send,

§

impl<P> Sync for Id<P>
where P: Sync,

§

impl<P> Unpin for Id<P>
where P: Unpin,

§

impl<P> UnwindSafe for Id<P>
where P: UnwindSafe,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.