namefn

Crates.ionamefn
lib.rsnamefn
version0.1.3
sourcesrc
created_at2023-09-06 15:04:56.158513
updated_at2023-09-07 10:54:16.836088
descriptionAdds a macro to retrive the name of the current function
homepagehttps://github.com/zoolq/tusk/tree/master/namefn
repositoryhttps://github.com/zoolq/tusk/tree/master/namefn
max_upload_size
id965370
size4,945
Felix (zoolq)

documentation

README

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.

Commit count: 0

cargo fmt