Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

borrow-splitting: Use take instead of replace #391

Merged
merged 1 commit into from
Jan 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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