Alex Rutar's Blog · Nov 19, 2025
(Un)safely moving elements out of borrowed data
0Sign in to vote or save
This site does not allow itself to be embedded. You can still read it on the original site — the toolbar below keeps your place in the directory.
Temporarily moving elements out of collections A recurring pattern when working with collections is the following. Suppose I have a collection, like a Vec<T> , and suppose I would like to take an element out and replace it with a new one. Fortunately for us, holding a mutable reference is almost the same as having ownership, so we can for example use replace : fn replace_at_index < T > ( vec : &…
Comments
Nothing yet. Say the first thing.
Sign in to join the conversation.