Crates.io | namefn |
lib.rs | namefn |
version | 0.1.3 |
source | src |
created_at | 2023-09-06 15:04:56.158513 |
updated_at | 2023-09-07 10:54:16.836088 |
description | Adds a macro to retrive the name of the current function |
homepage | https://github.com/zoolq/tusk/tree/master/namefn |
repository | https://github.com/zoolq/tusk/tree/master/namefn |
max_upload_size | |
id | 965370 |
size | 4,945 |
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.
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.