Macro zebra_test::args

source ·
macro_rules! args {
    ( @started $args:ident $(,)* ) => { ... };
    (
        @started $args:ident
        $parameter:tt : $argument:expr $(,)*
    ) => { ... };
    (
        @started $args:ident
        $argument:expr $(,)*
    ) => { ... };
    (
        @started $args:ident
        $parameter:tt : $argument:expr
        , $( $remaining_arguments:tt )+
    ) => { ... };
    (
        @started $args:ident
        $argument:expr
        , $( $remaining_arguments:tt )*
    ) => { ... };
    ( $( $arguments:tt )* ) => { ... };
}
Expand description

Helper macro to create a list of arguments in an Arguments instance.

Accepts items separated by commas, where an item is either:

  • a lone argument obtained from an expression
  • a key-value pair in the form "key": value_expression

The items are added to a new Arguments instance in order.

§Implementation details

This macro is called recursively, and can run into a macro recursion limit if the list of items is very long.

The first step of the macro is to create a new scope with an args binding to a new empty Arguments list. That binding is returned from the scope, so the macro’s generated code is an expression that creates the argument list. Once the scope is created, a @started tag is prefixed to the recursive calls, which then individually add each item.