Skip to content

Implement a `signature!` macro

Hugo requested to merge WhyNotHugo/zbus:signature-macro into main

This allows creating Signature instances who's signature definition is validated at compile-time, rather than at runtime. This is ideal for all those usages when the signature is just hard-coded, since the check and .unwrap() in the code are mostly noise with no added value.

The macro will provide clear feedback if the input is invalid, either at compile time, or via IDE integrations (e.g.: when using rust_analyzer).

Only tests for a working case have been included, since it's not possible to compile a failing case.

Some examples of errors for invalid input:

error: invalid value: character `0`, expected a valid signature character
   --> zbus_macros/tests/tests.rs:251:16
    |
251 |     signature!("0ss");
    |                ^^^^^

And:

error: unexpected token
 --> src/lib.rs:355:16
  |
6 |     signature!("ss", 1);
  |                    ^
Edited by Hugo

Merge request reports

Loading