Skip to content

Instantly share code, notes, and snippets.

Created April 10, 2016 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/0dcd62a61ce262fe1a49c8cc279b7526 to your computer and use it in GitHub Desktop.
Save anonymous/0dcd62a61ce262fe1a49c8cc279b7526 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