::function_name

Function attribute #[named] that generates a function_name! macro in the scope of the function's body.

The generated function_name!() is a macro that expands to the name of the annotated function, as a string literal.

Repository Latest version Documentation MSRV unsafe forbidden no_std compatible License CI

Examples

```rust use ::function_name::named;

[named]

fn mysuperduperfunction () { asserteq!( functionname!(), "mysuperduperfunction", ); } ```

Since the generated function_name! expands to a string literal, it can be used with other macros such as concat!:

```rust

[macrouse] extern crate functionname;

macrorules! functionpath {() => (concat!( modulepath!(), "::", functionname!() ))}

pub mod foo { pub mod bar { #[named] pub fn baz () { asserteq!( functionpath!(), [ env!("CARGOPKGNAME"), "foo", "bar", "baz", ].join("::"), ); } } } ```