等价于Rust中的__func__或__FUNCTION__吗? [英] Equivalent of __func__ or __FUNCTION__ in Rust?

查看:73
本文介绍了等价于Rust中的__func__或__FUNCTION__吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C和C ++中,您可以通过C99& C的__func__宏获取当前正在执行的函数的名称. C ++ 11和___FUNCTION___用于MSVC.

In C and C++ you can get the name of the currently executing function through the __func__ macro with C99 & C++11 and ___FUNCTION___ for MSVC.

Rust中有与之等效的东西吗?

Is there an equivalent of this in Rust?

C中__func__的示例:

#include "stdio.h"

void funny_hello() {
    printf ("Hello from %s\n", __func__);
}

int main() {
    funny_hello();
}

输出Hello from funny_hello.

推荐答案

有一个 RFC ,但从未得到同意或实施.

There was an RFC about this, but it was never agreed upon or implemented.

缺席的理由:

总的来说,我认为我们当中没有人给予过分的 从长远角度考虑这些调试相关"宏 稳定.他们中的大多数似乎相当无害,但致力于 永远为所有Rust程序提供所有这些都是强大的 做出承诺.我们不妨简要考虑一下这些故事的故事 宏,并考虑添加此新宏."

"In general I don't think any of us have given an inordinate amount of thought to these "debugging related" macros in terms of long term stability. Most of them seem fairly harmless, but committing to provide all of them for all Rust programs forever is a strong commitment to make. We may want to briefly consider the story of these macros in conjunction with considering adding this new macro."

也许Rust将来会有类似的东西,
但是目前,您将需要依靠自己的标记.

Maybe Rust will have something comparable in the future,
but for now you will need to rely on your own tagging.

旁注: __FUNCTION__是非标准的,__func__存在于C99/C ++ 11中.

side note: __FUNCTION__ is non standard, __func__ exists in C99 / C++11.

这篇关于等价于Rust中的__func__或__FUNCTION__吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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