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

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

问题描述

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

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?

没有.真的,真的没有.超级一点也没有.

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

我想使用一个通用前缀.

I would like to have use a common prefix.

将它们全部放在 mod 中.

Put them all in a mod instead.

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

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