macro_rules! at_modules {
(
$size:expr;
$( $name:expr => $module:ident ),* $(,)?
) => { ... };
}Expand description
Macro to define AT command modules
Creates a static array of command names and their associated context handlers.
§Warning
This macro uses unsafe to create mutable references to static data.
It is only suitable for single-threaded embedded contexts.
§Limitations
- Unsafe: Requires
unsafeblocks to use - Single-threaded only: Not safe for RTOS or multi-threaded environments
- Limited flexibility: Cannot mix different handler types
§Example
use at_parser_rs::at_modules;
use at_parser_rs::context::AtContext;
const SIZE: usize = 64;
static mut ECHO: EchoModule = EchoModule { echo: false };
static mut RESET: ResetModule = ResetModule;
at_modules! {
SIZE;
"AT+ECHO" => ECHO,
"AT+RST" => RESET,
}§Recommended Alternative
For most use cases, prefer the manual approach:
const SIZE: usize = 64;
let commands: &mut [(&str, &mut dyn AtContext<SIZE>)] = &mut [
("AT+ECHO", &mut echo_handler),
("AT+RST", &mut reset_handler),
];
parser.set_commands(commands);