Basically rust doesn't support default parameter value, but you can still do something equivalent with either of those two solutions
xxxxxxxxxx
fn add(a: Option<i32>, b: Option<i32>) -> i32 {
a.unwrap_or(1) + b.unwrap_or(2)
}
add(None, None) // return 3
add(None, 9) // return 10
add(7) // error, the None are required
// Or alternativelly
fn add(a: i32, b: i32) -> i32 {
a + b
}
macro_rules! add {
($a: expr) => {
add($a, 2)
};
() => {
add(1, 2)
};
}
add!() // return 3
add!(4) // return 6
add!(,9) // error, this can't be done with macro