macro_rules! can_id {
($n:expr) => { ... };
(standard: $n:expr) => { ... };
(extended: $n:expr) => { ... };
}
Expand description
Construct an CanId
(standard or extended) that is checked at compile time.
You can use any expression that can be evaluated at compile time and results in a u32
.
By default, if the value fits in a standard CAN ID, a standard CAN ID is created. You can also explicitly ask for a standard or extended ID.
Usage:
let id: CanId = can_id!(0x100 | 0x005);
assert2::let_assert!(CanId::Standard(id) = id);
assert2::assert!(id.as_u16() == 0x105);
Force construction of a CanId::Standard
(does not compile because the ID only fits as an extended ID):
ⓘ
let id: CanId = id!(standard: 0x10 << 16 | 0x50);
Force construction of a CanId::Extended
:
let id: CanId = can_id!(extended: 0x100 | 0x005);
assert2::let_assert!(CanId::Extended(id) = id);
assert2::assert!(id.as_u32() == 0x105);