Skip to content

Instantly share code, notes, and snippets.

@gorn
Last active August 13, 2018 16:52
Show Gist options
  • Save gorn/5286602d9f6d2ea8ae4ffc6d00350b45 to your computer and use it in GitHub Desktop.
Save gorn/5286602d9f6d2ea8ae4ffc6d00350b45 to your computer and use it in GitHub Desktop.
rustproblem
fn main() {
  let adata = Data { number: 1, number2: 7};
  let mut t = Tester {data : None};
  // something

  t.set_data(adata);
  assert_eq!(t.data.unwrap().number, 1);
}

struct Tester {
  data: Option<Data>
}

impl Tester {
  fn set_data(mut self, bdata: Data) {
    self.data = Some(bdata)
  }
}

struct Data {
  number : i32,
  number2 : i32
}
Compiling mover v0.1.0 (file:///home/gorn/nextcloud/viptrader/rust/mover)
error[E0382]: use of moved value: `t.data`
--> mover/src/main.rs:7:14
|
6 | t.set_data(adata);
| - value moved here
7 | assert_eq!(t.data.unwrap().number, 1);
| ^^^^^^ value used here after move
|
= note: move occurs because `t` has type `Tester`, which does not implement the `Copy` trait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment