如何在宏内给标识符加上前缀/后缀? [英] How to prefix/suffix identifiers within a macro?

查看:101
本文介绍了如何在宏内给标识符加上前缀/后缀?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用定义函数的宏时,是否可以在函数中添加前缀?

When using a macro that defines a function, is it possible to add a prefix to the function?

macro_rules! my_test {
    ($id:ident, $arg:expr) => {
        #[test]
        fn $id() {
            my_test_impl(stringify!($id), $arg);
        }
    }
}

例如,fn my_test_$id() {

我正在使用可能以数字开头的标识符定义测试,并且我想使用通用前缀.

I'm defining tests using an identifier which may begin with numbers, and I would like to use a common prefix.

推荐答案

[...]是否可以在函数中添加前缀?

[...] is it possible to add a prefix to the function?

不.真的,真的不行. Super 甚至一点也没有.

No. Really, really no. Super totally not at all even in the slightest.

我想使用一个通用前缀.

I would like to have use a common prefix.

将它们全部放在mod中.

这篇关于如何在宏内给标识符加上前缀/后缀?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆