Equivalent of __func__ or __FUNCTION__ in Rust?

前端 未结 3 1156
独厮守ぢ
独厮守ぢ 2021-02-07 02:37

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.

3条回答
  •  后悔当初
    2021-02-07 03:19

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

    The rationale for its absence:

    "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."

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

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

提交回复
热议问题