aboutsummaryrefslogtreecommitdiff
path: root/src/util.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.rs')
-rw-r--r--src/util.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/util.rs b/src/util.rs
index 4fc4448..9325e9e 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -3,6 +3,35 @@
use core::marker::Sized;
+macro_rules! enum_cmd {
+ (
+ $(#[$outer:meta])*
+ pub enum $name:ident {
+ $($var:ident($cmd:ident) = $num:expr),+
+ $(,)*
+ }
+ ) => {
+ enum_u8! {
+ $(#[$outer])*
+ pub enum $name {
+ $(
+ $var = $num,
+ )*
+ }
+ }
+
+ impl $name {
+ pub fn execute(&self, data: &[u8], buf: &mut [u8]) -> CommandStatus {
+ match *self {
+ $(
+ $name::$var => $cmd::execute_raw(data, buf),
+ )*
+ }
+ }
+ }
+ };
+}
+
macro_rules! enum_u8 {
(
$(#[$outer:meta])*