Skip to content

Commit

Permalink
borrow-splitting: Use take instead of replace (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
xy2i authored Jan 5, 2023
1 parent 8ca2612 commit 03fa5be
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/borrow-splitting.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl<'a, T> Iterator for IterMut<'a, T> {
type Item = &'a mut T;

fn next(&mut self) -> Option<Self::Item> {
let slice = mem::replace(&mut self.0, &mut []);
let slice = mem::take(&mut self.0);
if slice.is_empty() { return None; }

let (l, r) = slice.split_at_mut(1);
Expand All @@ -170,7 +170,7 @@ impl<'a, T> Iterator for IterMut<'a, T> {

impl<'a, T> DoubleEndedIterator for IterMut<'a, T> {
fn next_back(&mut self) -> Option<Self::Item> {
let slice = mem::replace(&mut self.0, &mut []);
let slice = mem::take(&mut self.0);
if slice.is_empty() { return None; }

let new_len = slice.len() - 1;
Expand Down

0 comments on commit 03fa5be

Please sign in to comment.