From f3cf322f8d9ad582006e8a5fe94a3ee3f3580b04 Mon Sep 17 00:00:00 2001 From: Alex van de Sandt Date: Thu, 07 May 2026 00:28:48 +0000 Subject: [PATCH] Make command macro more hygenic --- src/command/macros.rs | 29 +++++++++++++++-------------- src/command/bc125at/mod.rs | 2 +- 2 file(s) changed, 16 insertion(s)(+), 15 deletion(s)(-) diff --git a/src/command/macros.rs b/src/command/macros.rs --- a/src/command/macros.rs +++ b/src/command/macros.rs @@ -2,33 +2,29 @@ ($text:literal: $name:ident) => { pub struct $name; - impl Command for $name { + impl crate::command::Command for $name { const TEXT: &'static [u8] = $text; - type Params = NoParams; - type Response = OkResponse; + type Params = crate::command::NoParams; + type Response = crate::command::OkResponse; - fn params(&self) -> &Self::Params { - &NoParams - } + command!(@no_params_fn); } }; - ($text:literal: $name:ident => $response:ident) => { + ($text:literal: $name:ident => $response:ty) => { pub struct $name; - impl Command for $name { + impl crate::command::Command for $name { const TEXT: &'static [u8] = $text; - type Params = NoParams; + type Params = crate::command::NoParams; type Response = $response; - fn params(&self) -> &Self::Params { - &NoParams - } + command!(@no_params_fn); } }; - ($text:literal: $name:ident($param_set:ident) => $response:ident) => { + ($text:literal: $name:ident($param_set:ty) => $response:ty) => { pub struct $name(pub $param_set); - impl Command for $name { + impl crate::command::Command for $name { const TEXT: &'static [u8] = $text; type Params = $param_set; type Response = $response; @@ -36,6 +32,11 @@ fn params(&self) -> &Self::Params { &self.0 } + } + }; + (@no_params_fn) => { + fn params(&self) -> &crate::command::NoParams { + &crate::command::NoParams } }; } diff --git a/src/command/bc125at/mod.rs b/src/command/bc125at/mod.rs --- a/src/command/bc125at/mod.rs +++ b/src/command/bc125at/mod.rs @@ -1,6 +1,6 @@ use std::{num::ParseIntError, str::Utf8Error}; -use crate::command::{Command, NoParams, OkResponse, Params, Response, command}; +use crate::command::{OkResponse, Params, Response, command}; use super::ParamBuffer; -- tangled.sh