#splitborrows — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #splitborrows, aggregated by home.social.
-
@wtfrank You can use a concept called "Split Borrows" or "Borrow Splitting":
https://doc.rust-lang.org/nomicon/borrow-splitting.html
Here is a playground that shows it:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=607b3986ab9c04a3b918e55c5a2d2163It boils down to the following:
You can split your vector (or rather slice) into two mutable parts and mutate each half individually, by using `split_at_mut` on slices:See docs in std:
https://doc.rust-lang.org/std/primitive.slice.html#method.split_at_mut