Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code shared from the Rust Playground
// 1. Run as-is.
// 2. Comment in the section marked (2). Read the compiler error.
// 3. Comment in the section marked (3). Look how output differs from (1).
use std::mem;
fn print_size_of<T>(_t: &T) {
println!("size: {}", mem::size_of::<T>());
}
fn main() {
let print_xs;
{
let xs = vec![1, 2, 3, 4];
print_xs = /* (3) move */ || {
for (i, x) in xs.iter().enumerate() {
println!("{}: {}", i, x);
}
};
print_size_of(&print_xs);
}
/* (2) print_xs(); */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.