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

#64 in Procedural macros

Download history 14691/week @ 2024-07-24 13462/week @ 2024-07-31 13355/week @ 2024-08-07 14223/week @ 2024-08-14 15619/week @ 2024-08-21 16866/week @ 2024-08-28 20296/week @ 2024-09-04 16218/week @ 2024-09-11 14923/week @ 2024-09-18 16801/week @ 2024-09-25 15878/week @ 2024-10-02 16899/week @ 2024-10-09 17114/week @ 2024-10-16 15343/week @ 2024-10-23 16116/week @ 2024-10-30 16638/week @ 2024-11-06

68,868 downloads per month
Used in 112 crates (64 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