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 produces a string literal if the function has no generic parameters,
or the generic parameters are explicitly excluded with ::<..>. Otherwise, it
produces a String.
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>");