8 releases

0.3.0 May 11, 2022
0.2.3 May 10, 2022
0.2.0 Jun 21, 2019
0.1.0 Jun 19, 2019

#45 in #proc-macro-attributes

Download history 22334/week @ 2024-03-14 19972/week @ 2024-03-21 19391/week @ 2024-03-28 19278/week @ 2024-04-04 20210/week @ 2024-04-11 20026/week @ 2024-04-18 18061/week @ 2024-04-25 14449/week @ 2024-05-02 16211/week @ 2024-05-09 18383/week @ 2024-05-16 13826/week @ 2024-05-23 18242/week @ 2024-05-30 16440/week @ 2024-06-06 14262/week @ 2024-06-13 18791/week @ 2024-06-20 13625/week @ 2024-06-27

67,951 downloads per month
Used in 99 crates (via function_name)

MIT license

6KB
133 lines

::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

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

No runtime deps