Skip to content

Instantly share code, notes, and snippets.

@levinotik
Forked from anonymous/playground.rs
Created April 10, 2016 21:05
Show Gist options
  • Save levinotik/fc07d890e0e20e3165607c0435b5656c to your computer and use it in GitHub Desktop.
Save levinotik/fc07d890e0e20e3165607c0435b5656c to your computer and use it in GitHub Desktop.
Shared via Rust Playground
fn main() {
// No good because we move v to v2
// which creates a copy of the pointer
// which means we have two pointers
// to the content of the vector on the heap
// this violates safety guarantees
// by introducing a data race
// therefore Rust forbids using v after the move
// +---------+------+----------------+
// | address | name | value |
// +---------+------+----------------+
// | 1 | v2 | ->(2 ^ 30) - 1 |
// | 0 | v | ->(2 ^ 30) - 1 |
// +---------+------+----------------+
let v = vec![1, 2, 3];
let v2 = v;
println!("{:?}", v);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment