Default function arguments in Rust
@lebyy▲ 0 net votes
Problem: Is it possible to create a function with a default argument? fn add(a: int = 1, b: int = 2) { a + b } Fix (from the top answer): Since default arguments are not supported you can get a similar behavior using Option<T> fn add(a: Option<i32>, b: Option<i32>) -> i32 { a.unwrap_or(1) + b.unwrap_or(2) } // Usage example: let r This accomplishes the objective of having the default value and the function coded only once (instead of in every call),…