Is it possible to declare variables procedurally using Rust macros?

后端 未结 4 758
轮回少年
轮回少年 2020-11-27 07:55

Basically, there are two parts to this question:

  1. Can you pass an unknown identifier to a macro in Rust?

  2. Can you combine strings to generate

4条回答
  •  遥遥无期
    2020-11-27 08:16

    There is also https://github.com/dtolnay/paste, which works well in casese where concat_idents is underpowered or in cases where you can't target the nightly compiler.

    macro_rules! foo_macro {
        ( $( $name:ident ),+ ) => {
            paste::item! {
                #[test]
                fn []() {
                    assert! false
                }
            }
        };
    }
    

提交回复
热议问题