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

#56 in Procedural macros

Download history 13766/week @ 2023-12-15 10499/week @ 2023-12-22 10167/week @ 2023-12-29 15866/week @ 2024-01-05 16769/week @ 2024-01-12 17739/week @ 2024-01-19 15915/week @ 2024-01-26 22318/week @ 2024-02-02 21458/week @ 2024-02-09 20059/week @ 2024-02-16 22170/week @ 2024-02-23 20634/week @ 2024-03-01 19302/week @ 2024-03-08 21994/week @ 2024-03-15 21201/week @ 2024-03-22 15070/week @ 2024-03-29

81,809 downloads per month
Used in 93 crates (58 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