Search code examples
functionparametersargumentsrust

Default function arguments in Rust


Is it possible to create a function with a default argument?

fn add(a: int = 1, b: int = 2) { a + b }

Solution

  • No, it is not at present. I think it likely that it will eventually be implemented, but there’s no active work in this space at present.

    The typical technique employed here is to use functions or methods with different names and signatures.