Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() {
- let mut t: u64 = 0;
- // Vec is reference to memory in the heap, v is on stack
- let mut v: Vec<u64> = Vec::with_capacity(100);
- assert_eq!(0, v.len());
- for i in 0..100 {
- v.push(i)
- }
- for e in v {
- t += e
- }
- // can't say 'drop(v);' here, because the vector gets "used up" in the
- // for loop (takes each element and moves it out into e). Cant' reuse v
- // without using 'v.clone()' or 'v.iter()'
- println!("Sum was {}", t);
- // implicit free call here; or can say 'drop(t);'
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement