Warning
This post was published 36 days ago. The information described in this article may have changed.
Given a variable vec
of type Vec<Item>
where Item
is not Copy
,
Simply writing vec[index]
would cause error:
return vec[index]; // error: cannot move out of `vec`
So I must wrote this convoluted code:
vec.truncate(index);
return vec.pop().unwrap();
This looks inefficient and stupid.
Is there a better way? (I don't need the rest of vec
after I have vec[index]
)
11 posts - 8 participants
🏷️ rust_feed