3 unstable releases

0.2.0 Jun 21, 2019
0.1.1 Jun 19, 2019
0.1.0 Jun 19, 2019

#1300 in Rust patterns

Download history 4986/week @ 2021-09-26 3799/week @ 2021-10-03 7125/week @ 2021-10-10 4205/week @ 2021-10-17 3520/week @ 2021-10-24 4647/week @ 2021-10-31 4480/week @ 2021-11-07 5557/week @ 2021-11-14 2092/week @ 2021-11-21 4416/week @ 2021-11-28 1089/week @ 2021-12-05 4113/week @ 2021-12-12 957/week @ 2021-12-19 359/week @ 2021-12-26 2422/week @ 2022-01-02 5206/week @ 2022-01-09

8,970 downloads per month
Used in 9 crates (8 directly)

MIT license

4KB

#[named]

Function attribute 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 License

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

~2MB
~53K SLoC