Skip to content

Commit

Permalink
Add drain_and_swap to SwapVec
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkleiny committed Aug 9, 2024
1 parent 0623874 commit 4673ba9
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions core/common/src/collections/swapvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ impl<T> SwapVec<T> {
}
}

/// Swaps the active [`Vec`] and drains the now-inactive one.
pub fn drain_and_swap(&mut self, range: RangeFull) -> std::vec::Drain<T> {
match self.status {
Status::Red => {
self.status = Status::Green;
self.red.drain(range)
}
Status::Green => {
self.status = Status::Red;
self.green.drain(range)
}
}
}

/// Swaps the active [`Vec`] with the inactive one
/// returning the previously-active [`Vec`].
pub fn swap(&mut self) -> &mut Vec<T> {
Expand Down

0 comments on commit 4673ba9

Please sign in to comment.