Skip to content

Commit 5fc3438

Browse files
Add compile-time check that request ids are distinct
If two requests are given the same u8 id, this will cause a compile failure
1 parent 77e89bd commit 5fc3438

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/api/macros.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ macro_rules! generate_enums {
2121
)*
2222
}
2323

24+
const _: () = {
25+
// Compile failure if a request ID is reused
26+
fn _check_request_id_conflicts() {
27+
match 0u8 {
28+
0 => unreachable!(),
29+
$(
30+
$index => unreachable!(),
31+
)*
32+
_ => todo!()
33+
}
34+
}
35+
};
36+
2437
impl From<&Request> for u8 {
2538
fn from(request: &Request) -> u8 {
2639
match request {

0 commit comments

Comments
 (0)