Hi, I am trying to write a simple class, and get a use of moved value: self
error. Any suggestion? Thanks!
pub struct Robot {}
impl Robot {
pub fn new() -> Self {
Robot {}
}
pub fn advance(mut self) -> Self {
self
}
pub fn instructions(mut self) -> Self {
self.advance();
self
}
}
fn main() {}
error[E0382]: use of moved value: `self`
--> src\main.rs:12:9
|
10 | pub fn instructions(mut self) -> Self {
| -------- move occurs because `self` has type `Robot`, which does not implement the `Copy` trait
11 | self.advance();
| --------- `self` moved due to this method call
12 | self
| ^^^^ value used here after move
|
note: this function takes ownership of the receiver `self`, which moves `self`
--> src\main.rs:7:24
|
7 | pub fn advance(mut self) -> Self {
| ^^^^