function_name 0.2.1

macro that expands to the name of the annotated function
docs.rs failed to build function_name-0.2.1
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: function_name-0.3.0

#[named]

Function attribute 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 License

Examples

use ::function_name::named;

#[named]
fn my_super_duper_function ()
{
    assert_eq!(
        function_name!(),
        "my_super_duper_function",
    );
}

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

#[macro_use] extern crate function_name;

macro_rules! function_path {() => (concat!(
    module_path!(), "::", function_name!()
))}

pub mod foo {
    pub mod bar {
        #[named]
        pub fn baz ()
        {
            assert_eq!(
                function_path!(),
                [
                    env!("CARGO_PKG_NAME"),
                    "foo", "bar",
                    "baz",
                ].join("::"),
            );
        }
    }
}