Created
November 13, 2019 20:37
-
-
Save rust-play/cea0754c666a71783b01ddd99ede57c4 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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