9 releases

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

#46 in Procedural macros

Download history 14533/week @ 2024-11-29 20551/week @ 2024-12-06 17047/week @ 2024-12-13 9422/week @ 2024-12-20 7918/week @ 2024-12-27 21145/week @ 2025-01-03 27758/week @ 2025-01-10 25556/week @ 2025-01-17 25643/week @ 2025-01-24 27804/week @ 2025-01-31 27713/week @ 2025-02-07 35466/week @ 2025-02-14 31582/week @ 2025-02-21 29326/week @ 2025-02-28 38728/week @ 2025-03-07 40830/week @ 2025-03-14

148,383 downloads per month
Used in 134 crates (67 directly)

MIT license

6KB

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

Dependencies