A local function in Rust
Solution 1:
Yes, you can define functions inside functions:
fn method1() {
fn inner_method1() {
println!("Hello");
}
inner_method1();
inner_method1();
}
However, inner functions don't have access to the outer scope. They're just normal functions that are not accessible from outside the function. You could, however, pass the variables to the function as arguments. To define a function with a particular signature that can still access variables from the outer scope, you must use closures.