Skip to content

Commit 02ac461

Browse files
authored
refactor: rewrite transfer::Allowed with macros (#107)
1 parent eb9ab30 commit 02ac461

File tree

1 file changed

+38
-36
lines changed

1 file changed

+38
-36
lines changed

src/ring/trb/transfer.rs

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,50 +29,52 @@ allowed! {
2929
}
3030
impl Allowed {
3131
/// Sets the value of the Interrupt On Completion field.
32-
// Unavoidable because the match arms has to be the same return types.
33-
#[allow(clippy::too_many_lines)]
3432
pub fn set_interrupt_on_completion(&mut self, ioc: bool) {
35-
match self {
36-
Allowed::Normal(ref mut n) => {
37-
n.set_interrupt_on_completion(ioc);
38-
}
39-
Allowed::SetupStage(ref mut s) => {
40-
s.set_interrupt_on_completion(ioc);
41-
}
42-
Allowed::DataStage(ref mut d) => {
43-
d.set_interrupt_on_completion(ioc);
44-
}
45-
Allowed::StatusStage(ref mut s) => {
46-
s.set_interrupt_on_completion(ioc);
47-
}
48-
Allowed::Isoch(ref mut i) => {
49-
i.set_interrupt_on_completion(ioc);
50-
}
51-
Allowed::Link(ref mut l) => {
52-
l.set_interrupt_on_completion(ioc);
53-
}
54-
Allowed::EventData(ref mut e) => {
55-
e.set_interrupt_on_completion(ioc);
56-
}
57-
Allowed::Noop(ref mut n) => {
58-
n.set_interrupt_on_completion(ioc);
59-
}
33+
macro_rules! arm{
34+
($($variant:ident),*)=>{
35+
match self {
36+
$(Self::$variant(ref mut x)=>{
37+
x.set_interrupt_on_completion(ioc);
38+
},)*
39+
}
40+
};
6041
}
42+
43+
arm!(
44+
Normal,
45+
SetupStage,
46+
DataStage,
47+
StatusStage,
48+
Isoch,
49+
Link,
50+
EventData,
51+
Noop
52+
);
6153
}
6254

6355
/// Returns the value of the Interrupt On Completion field.
6456
#[must_use]
6557
pub fn interrupt_on_completion(&self) -> bool {
66-
match self {
67-
Allowed::Normal(n) => n.interrupt_on_completion(),
68-
Allowed::SetupStage(s) => s.interrupt_on_completion(),
69-
Allowed::DataStage(d) => d.interrupt_on_completion(),
70-
Allowed::StatusStage(s) => s.interrupt_on_completion(),
71-
Allowed::Isoch(i) => i.interrupt_on_completion(),
72-
Allowed::Link(l) => l.interrupt_on_completion(),
73-
Allowed::EventData(e) => e.interrupt_on_completion(),
74-
Allowed::Noop(n) => n.interrupt_on_completion(),
58+
macro_rules! arm{
59+
($($variant:ident),*)=>{
60+
match self {
61+
$(Self::$variant(x)=>{
62+
x.interrupt_on_completion()
63+
},)*
64+
}
65+
};
7566
}
67+
68+
arm!(
69+
Normal,
70+
SetupStage,
71+
DataStage,
72+
StatusStage,
73+
Isoch,
74+
Link,
75+
EventData,
76+
Noop
77+
)
7678
}
7779
}
7880

0 commit comments

Comments
 (0)