Rust doesn't support default function arguments and named function arguments.
This crate generate an macro interface for a given function that can be invoked with named arguments and fill the default argument, meanwhile keep the old function intact.
In order to generate macro for a function, we just need to wrap the definition with duang!{...}
.
```rust use duang::duang;
duang!(
pub fn foo
rust
use demo_duang::foo;
// pass
assert_eq!(foo!(1, c = 30, b = -2.0), (1, -2.0, 30));
// pass
assert_eq!(foo!(a = 10), (10, 13.0, 100));
// fail
// foo!(1,c=30,c=2);
In order to use the generated macro in other crate, users should add $crate
and path of the variable used.
Also, the variable should be visible(pub
) for the scope where the macro is invoked.
rust
mod bar {
use duang::duang;
pub static NUM: i32 = 42;
duang!(
pub fn foo(a: i32 = $crate::bar::NUM) -> i32 { a }
);
}
fn main() {
use bar::foo;
assert_eq!(foo!(), 42);
}
fn foo((a,_): (i32, i32))
is illegal.License: MIT