#macro #proc-macro #proc-macro-attribute #name #function-name

macro function_name-proc-macro

macro that expands to the name of the annotated function

2 unstable releases

0.2.0 Jun 21, 2019
0.1.0 Jun 19, 2019

#4 in #proc-macro-attribute

Download history 3870/week @ 2021-10-04 6889/week @ 2021-10-11 4126/week @ 2021-10-18 3509/week @ 2021-10-25 4672/week @ 2021-11-01 4479/week @ 2021-11-08 5524/week @ 2021-11-15 2082/week @ 2021-11-22 4398/week @ 2021-11-29 1114/week @ 2021-12-06 4089/week @ 2021-12-13 949/week @ 2021-12-20 399/week @ 2021-12-27 2622/week @ 2022-01-03 5162/week @ 2022-01-10 3313/week @ 2022-01-17

11,557 downloads per month
Used in 10 crates (via function_name)

Custom license

4KB
67 lines

#[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("::"),
            );
        }
    }
}

Dependencies

~2MB
~53K SLoC