Crates.io | function_name |
lib.rs | function_name |
version | 0.3.0 |
source | src |
created_at | 2019-06-19 16:51:15.306823 |
updated_at | 2022-05-11 09:04:00.868983 |
description | macro that expands to the name of the annotated function |
homepage | https://crates.io/crates/function_name |
repository | https://github.com/danielhenrymantilla/rust-function_name |
max_upload_size | |
id | 142123 |
size | 10,779 |
::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.
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("::"),
);
}
}
}