Move out of what exactly?

What does this mean?

cannot move out of input because it is borrowed

What does something move out of input? I don't think the language works here.

I read the chapter on borrowing in the book and I found it absurdly terse for one of the most complicated parts of the language. Now I'm trying to iterate in a nested loop and am getting this.

It means you are using input in some manner that destroys it, or gives exclusive ownership of it away to someone else.

I get that the first iteration 'destroys' it. Destroy there means: "makes it unavailable in the local scope"?

But who or what moved into input and why is it trying to move out?

I get moving in and out of scope, but this is a variable.

To know this, we'd need to see the code that fails to compile. You could share it via

It sounds like you should show the particular code in question. It depends on the situation, e.g. if you call the .into_iter method on a Vec, that destroys it because into_iter takes self rather than &self or &mut self.

In Rust we say that a variable “owns” its value. “Moving” a value means transferring it from one owner to another. We say that it moves out of the original variable and into some other location.

let foo = input; // moves a value out of `input` and into `foo`

or passing it to a function by value:

f(input); // moves a value out of `input` and into a parameter of `f`

or calling a method that takes its self argument by value:

// moves a value out of `input` and into the `self` parameter of `consume`
1 Like

I guess I'm implicitly calling into_iter on an iterator (not a Vec in this case) if I'm running a for loop?

But "destroy"? Nothing is destroyed, it is moved, so it's unavailable in the current scope, right? I don't get this "destroy" word.

I think I understand the concepts but I just don't get the language, especially the "move out of".

Who's moving out of what?

The value is moving out of one place (variable) and into another.

Aha……… that makes sense.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.