riot_wrappers

Macro static_command

Source
macro_rules! static_command {
    ( $modname:ident, $name:literal, $descr:literal, $fun:ident ) => { ... };
}
Available on riot_module_shell only.
Expand description

Make a function whose signature is fn(&mut Stdio, Args<'b>) -> impl Termination available through XFA in any RIOT shell, even when called throuch C. (The function’s signature may be more generic, eg. accepting an impl Write and an impl IntoIterator<&str>).

Compared to CommandList, this is limited by only taking functions and not closures – but that allows using it even in scenarios where CommandList’s hacks that reconstruct a full closure from something that’s only a plain function call in C are unavailable.

The modname identifier needs to be provided as a name that can be used for a private module created by the macro. The name literal is the command name as matched by the shell, with the descr literal shown next to it when running help. The fun is a local function of static lifetime that gets executed whenever the shell command is invoked.

§Example

fn do_echo(
        _stdio: &mut riot_wrappers::stdio::Stdio,
        args: riot_wrappers::shell::Args<'_>,
)
{
    use riot_wrappers::println;
    println!("Running args of run:");
    for a in args.iter() {
        println!("{:?}", a);
    }
}
riot_wrappers::static_command!(echo, "echo", "Print the arguments in separate lines", do_echo);