Skip to content

Instantly share code, notes, and snippets.

@ihcsim
Last active February 1, 2022 21:02
Show Gist options
  • Save ihcsim/d883afc26edf76dd7d3a4aa7d3970234 to your computer and use it in GitHub Desktop.
Save ihcsim/d883afc26edf76dd7d3a4aa7d3970234 to your computer and use it in GitHub Desktop.
$ cargo run
Compiling rust-ownership v0.1.0 (/home/isim/rust-ownership)
error[E0382]: borrow of moved value: `svcs`
--> src/main.rs:22:22
|
8 | let svcs = vec![
| ---- move occurs because `svcs` has type `Vec<Service>`, which does not implement the `Copy` trait
...
19 | for svc in svcs {
| ----
| |
| `svcs` moved due to this implicit call to `.into_iter()`
| help: consider borrowing to avoid moving into the for loop: `&svcs`
...
22 | println!("{:?}", svcs);
| ^^^^ value borrowed here after move
|
note: this function takes ownership of the receiver `self`, which moves `svcs`
--> /home/isim/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/collect.rs:234:18
|
234 | fn into_iter(self) -> Self::IntoIter;
| ^^^^
For more information about this error, try `rustc --explain E0382`.
error: could not compile `rust-ownership` due to previous error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment