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

#327 in Procedural macros

Download history 12011/week @ 2022-04-21 11986/week @ 2022-04-28 8595/week @ 2022-05-05 8382/week @ 2022-05-12 21847/week @ 2022-05-19 9898/week @ 2022-05-26 22377/week @ 2022-06-02 35291/week @ 2022-06-09 21878/week @ 2022-06-16 9851/week @ 2022-06-23 9625/week @ 2022-06-30 15469/week @ 2022-07-07 31720/week @ 2022-07-14 33100/week @ 2022-07-21 20897/week @ 2022-07-28 24808/week @ 2022-08-04

112,578 downloads per month
Used in 17 crates (via function_name)

MIT license

5KB
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