Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
:timing
:sccache 1Tips¶
Functions in a module is private by default. To make it public (so that it can called outside the module), you have to use the keyword
pub.
fn add1(x: i32, y: i32) -> i32 {
x + y
}add1(1, 2)3let add2 = |x: i32, y: i32| x + y;
add2(1, 2)Sorry, the type [closure@src/lib.rs:112:12: 112:34] cannot currently be persistedFunction Overload¶
Rust does not support function overloading. There are multiple alternative ways to the OOP-style function overloading in Rust.
Simply define different methods.
Use trait to simulation function overloading.
Default/Optional Arguments¶
Rust does not support optinal arguments for Functions. For more discussions, please refer to Optional arguments in Rust .