Scoped functions
- We can defined a function inside a function and then it will be only available in that scope.
- Surprisingly (or not) we can call the function anywhere inside the scope, even before its declaration.
examples/functions/scoped-functions/src/main.rs
fn main() { say_hi("before"); fn say_hi(text: &str) { println!("hi {text}"); } say_hi("after"); other(); } fn other() { println!("in other"); // cannot find function `say_hi` in this scope //say_hi("other"); }
hi before hi after in other