4 releases
0.1.3 | Sep 7, 2023 |
---|---|
0.1.2 | Sep 6, 2023 |
0.1.1 | Sep 6, 2023 |
0.1.0 | Sep 6, 2023 |
#2287 in Development tools
5KB
59 lines
namenf
The namefn crate provides a flag for retrieving the name of a function. Use the #[name]
flag to get the function name. You can access the name via the NAME
variable. The name is a &str
, by default.
This crate is extremely useful for logging and other tracking purposes.
Licensed under MIT.
Example
The basic functionality consists of getting the functions name via a const variable called NAME
.
use namefn::name;
#[namefn]
fn main() {
assert_eq!("main", NAME);
}
You can also crate a custom function name:
use namefn::name;
#[namefn(alias = "cool_name")]
fn uncool_name() {
assert_eq!("cool_name", NAME);
}
Here the name is cool_name
instead of uncool_name
.
If you for some reason already have a constant called name you can also rename the constant.
use namefn::name;
#[namefn(const = FUNCTION)]
fn main() {
assert_eq!("main", FUNCTION);
}
The name is still main
but the constant is now called FUNCTION
.
Note: If the const attribute is lowercase it will be converted to uppercase.
Dependencies
~245–700KB
~17K SLoC