From c740386d6bbb12feac4ab8df50883aa6c300ee83 Mon Sep 17 00:00:00 2001 From: occheung Date: Fri, 4 Sep 2020 17:52:37 +0800 Subject: [PATCH] scpi: add macro for command struct --- src/scpi.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/scpi.rs b/src/scpi.rs index ce7a202..672cada 100644 --- a/src/scpi.rs +++ b/src/scpi.rs @@ -131,7 +131,31 @@ impl Command for HelloWorldCommand { } } -pub struct Channel1SwitchCommand {} +macro_rules! declare_channel_commands { + ($($header: ident),*) => { + mashup! { + $( + m["channel0" $header] = Channel0 $header Command; + m["channel1" $header] = Channel1 $header Command; + m["channel2" $header] = Channel2 $header Command; + m["channel3" $header] = Channel3 $header Command; + )* + } + + m! { + $( + pub struct "channel0" $header {} + pub struct "channel1" $header {} + pub struct "channel2" $header {} + pub struct "channel3" $header {} + )* + } + }; +} + +declare_channel_commands!(Switch); + +// pub struct Channel1SwitchCommand {} impl Command for Channel1SwitchCommand { nquery!();