#macro #proc-macro #compile-time #function

macro func_

Proc macro to add function name constant within body of function

2 stable releases

1.0.1 Sep 25, 2023
1.0.0 Sep 21, 2023

#1982 in Procedural macros

40 downloads per month

BSL-1.0 license

6KB
71 lines

func_

Rust Crates.io Documentation

Proc macro to insert function name within body of function because Rust is incapable of doing simple things

Once type_name is stable in const context this macro can be replaced properly with simple function call on function type.

Usage

use func_::_func_;

#[_func_]
fn my_func() {
    assert_eq!(__func__, "my_func");
}

lib.rs:

Proc macro to insert function name within body of function

Usage

use func_::_func_;

#[_func_]
fn my_func() {
    assert_eq!(__func__, "my_func");

    println!("{__func__}: log with function name");
}

#[_func_]
fn my_generic_func<T>() {
    assert_eq!(__func__, "my_generic_func");

    println!("{__func__}: log with generic function name but without generics bullshit cuz why the would I want generics in my generic name?");
}

#[_func_]
const fn const_func() {
    assert!(__func__.len() == "const_func".len());
}

#[_func_]
async fn async_func() {
    assert_eq!(__func__, "async_func");
}

my_func();
my_generic_func::<u16>();
const_func();

No runtime deps