Default Args
Enables default arguments in rust by macro in zero cost. Just wrap function with default_args!
and macro with name of
function would be automatically generated to be used with default argument. See below for usage
use default_args;
// this would make a macro named `foo`
// and original function named `foo_`
default_args!
// in other codes...
assert_eq!; // foo(1, 100)
assert_eq!; // foo(1, 3)
assert_eq!; // foo(1, 5)
assert_eq!; // foo(1, 10)
More Features
Export
Add export in the front of the function and the macro would be exported. (add pub to export function with macro)
default_args!
Path of function
Macro just call the function in name, so you should import both macro and the function to use it. By writing the path of
this function, you can just only import the macro.
(path should start with crate
)
// then it would create `bar!()`
bar!;
Why do we have to write module?
std::module_path!
can resolve the module path of the function where it is declared. However, it can be resolved in runtime, not compile-time. I couldn't find a way to get module path in compile-time.