concat_idents!() { /* proc-macro */ }
Expand description

This macros makes it possible to concatenate identifiers at compile time and use them as normal. It’s an extension/replacement of std::concat_idents, since in comprassion to the std-solution, the idents here can be used everywhere.

§Usage:

§Basic usage

use concat_idents::concat_idents;

concat_idents!(fn_name = foo_, _, bar {
       fn fn_name() {
           // --snip--
       }
});

foo__bar();

§Generating Tests

macro_rules! generate_test {
   ($method:ident($lhs:ident, $rhs:ident)) => {
       concat_idents!(test_name = $method, _, $lhs, _, $rhs {
           #[test]
           fn test_name() {
               let _ = $lhs::default().$method($rhs::default());
           }
       });
   };
}

#[derive(Default)]
struct S(i32);
impl Add<i32> for S {
   // --snip--
}
impl Sub<i32> for S {
   // --snip--
}

generate_test!(add(S, i32));
generate_test!(sub(S, i32));