macro_rules! riot_main {
    ($main:ident) => { ... };
Expand description

To have a nice Rust main function, run the riot_main! macro with the name of your main function an item (ie. top level in a module) in your crate. The function identified by it must return something that implements the Termination trait.



fn main() {

Functions with multiple signatures are accepted:

  • fn main() – useful for very simple programs
  • fn main() -> impl Termination – prints the error message according to the Termination implementation (in particular, Result types with a Debug error are useful here)
  • fn main(tokens: StartToken) -> (impl Termination, EndToken) – this ensures that the program has full control over the main thread. As a StartToken allows doing things that require undoing before the thread may terminate (eg. subscribing it to messages), an EndToken needs to be produced before the thread can terminate with a message as above.
  • fn main(tokens: StartToken) -> ! – a frequently useful variation thereof for main loops that are loops anyway.