Is there a way around clone in this example?
I have the piece of code below, which works fine, but I am a bit bothered by the need for clone
inside the for loop. In principle, the vector is no longer needed after a.clear()
is called, so it could be consumed inside this loop, but the code won’t compile without clone
. Is there a clever way around this, that moves self.a[i].v
into the new AStruct
instead of cloning it?
Rust: is there a way around clone in this example?
I have the piece of code below, which works fine, but I am a bit bothered by the need for clone
inside the for loop. In principle, the vector is no longer needed after a.clear()
is called, so it could be consumed inside this loop, but the code won’t compile without clone
. Is there a clever way around this, that moves self.a[i].v
into the new AStruct
instead of cloning it?