forked from davidcole1340/mcp2515-rs
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacros.rs
42 lines (39 loc) · 1.2 KB
/
macros.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#[macro_export]
macro_rules! dummy {
($t:expr) => {
()
};
}
#[macro_export]
macro_rules! filter_def {
(
$(#[doc = $doc:expr])*
$name:ident($n:expr) => {
$(
$(#[doc = $filt_doc:expr])*
$filt:ident => $regs:expr
),*
}
) => {
$(#[doc = $doc])*
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "ufmt", derive(ufmt::derive::uDebug))]
pub enum $name {
$(
$(#[doc = $filt_doc])*
$filt,
)*
}
impl $name {
#[doc = concat!("All valid options for [`", stringify!($name), "`].")]
pub const ALL: [Self; <[_]>::len(&[$($crate::dummy!($filt)),*])] = [$(Self::$filt),*];
#[doc = concat!("Returns the `SIDH`, `SIDL`, `EID8`, `EID0` registers (in that order) based on the variant of [`", stringify!($name), "`].")]
pub const fn registers(self) -> [$crate::regs::Register; $n] {
match self {
$(Self::$filt => $regs,)*
}
}
}
};
}