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

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

问题描述

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

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?

__func__ 在 C 中的示例:

#include "stdio.h"

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

int main() {
    funny_hello();
}

输出 来自 fun_hello 的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天全站免登陆