Error

"closure may outlive the current function" — How to Fix

Fix the 'closure may outlive the current function' error by adding the `move` keyword to transfer ownership of captured variables into the closure.

Add the move keyword to the closure to force it to take ownership of captured variables instead of borrowing them. This ensures the closure owns the data it needs for its entire lifetime, even if the original function returns.

let data = vec![1, 2, 3];
let closure = move || {
    println!("{:?}", data);
};