of_function

Macro of_function 

Source
macro_rules! of_function {
    ($ident:ident) => { ... };
    ($ident:ident ::<..>) => { ... };
    ($ident:ident ::<$($arg:ty),*>) => { ... };
}
Expand description

Get the name of the given function.

Use ::<..> syntax to exclude generic parameters in the output, see examples.

This macro returns &'static str. It caches the result and subsequent calls have zero runtime overhead.

This macro checks that the identifier is valid in the current scope. If the identifier is renamed via refactoring tools, the macro call will be updated accordingly.

ยงExamples

fn my_function() {}
fn my_generic_function<T>() {}
fn my_generic_function_2args<T, U>() {}
assert_eq!(pretty_name::of_function!(my_function), "my_function");
assert_eq!(pretty_name::of_function!(my_generic_function::<..>), "my_generic_function");
assert_eq!(pretty_name::of_function!(my_generic_function::<u32>), "my_generic_function::<u32>");
assert_eq!(pretty_name::of_function!(my_generic_function_2args::<..>), "my_generic_function_2args");
assert_eq!(pretty_name::of_function!(my_generic_function_2args::<u32, String>), "my_generic_function_2args::<u32, String>");