Hello,
If I have a borrowed struct, how can I replace a field with a new value that is created while consuming the old one? For example:
struct A {}
struct B {
a: A
}
impl A {
fn updated(self) -> A { self }
}
impl B {
fn update(&mut self) {
self.a = self.a.updated();
}
}
This complains:
|
13 | self.a = self.a.updated();
| ^^^^^^ --------- `self.a` moved due to this method call
| |
| move occurs because `self.a` has type `experiment::A`, which does not implement the `Copy` trait
|
note: this function takes ownership of the receiver `self`, which moves `self.a`
--> src/experiment.rs:8:16
|
8 | fn updated(self) -> A { self }
| ^^^^
How can I implement this? Thanks!
Best, Oliver