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

#44 in #proc-macro-attributes

Download history 13666/week @ 2023-12-18 9301/week @ 2023-12-25 11540/week @ 2024-01-01 16263/week @ 2024-01-08 17284/week @ 2024-01-15 16449/week @ 2024-01-22 18033/week @ 2024-01-29 23012/week @ 2024-02-05 22039/week @ 2024-02-12 18342/week @ 2024-02-19 21748/week @ 2024-02-26 20940/week @ 2024-03-04 20675/week @ 2024-03-11 19011/week @ 2024-03-18 21660/week @ 2024-03-25 17629/week @ 2024-04-01

79,375 downloads per month
Used in 94 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