Rust, abstracted: lambda dropping

What is lambda dropping?

Lambda Dropping is a procedure in functional programming where a lambda, otherwise known as a function, is moved from an outer scope, to an inner scope. This move is often done for optimization purposes, or also for necessary implementation purposes.

Does Rust do lambda dropping automatically?

Rust does not perform lambda dropping.

What does manual lambda dropping look like?

Below we manually implement lambda dropping for a simple function that captures x, then multiplies by a value y.

fn main() {
   {
      fn inner(x: u64, y: u64) -> u64 {
         x*y
      }
      fn outer(x: u64) -> u64 {
         inner(x, 5)
      }
      println!("{}", outer(4));
   }
   {
      fn outer(x: u64) -> u64 {
         fn inner(x: u64, y: u64) -> u64 {
            x*y
         }
         inner(x, 5)
      }
      println!("{}", outer(3));
   }
}