Macro macro_magic_macros::forward_tokens

source ·
forward_tokens!() { /* proc-macro */ }
Expand description

“Forwards” the tokens of the specified exported item (specified by path as the first arg) to the specified proc or macro_rules! macro (specified by path as the second arg).

This is used internally as the basis for many of the other macros in this crate, but can also be useful in its own right in certain situations.

Note that the referenced item must have the #[export_tokens] attribute attached to it, or this will not work.

There is also an optional third argument called “extra” which allows you to forward arbitrary data to the target macro. This is used by #[import_tokens_attr] to pass the tokens for the attached item in addition to the tokens for the external item.

§Example

#[macro_export]
macro_rules! receiver {
    ($tokens:item) => {
        stringify!($tokens)
    };
}

let result = forward_tokens!(LionStruct, receiver);
assert_eq!(result, "struct LionStruct {}");