Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: moved InPlaceDrop into in_place_drop.rs
- Loading branch information
1 parent
a3f3fc5
commit 9e08ce7
Showing
2 changed files
with
28 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use core::ptr::{self}; | ||
use core::slice::{self}; | ||
|
||
// A helper struct for in-place iteration that drops the destination slice of iteration, | ||
// i.e. the head. The source slice (the tail) is dropped by IntoIter. | ||
pub (super) struct InPlaceDrop<T> { | ||
pub (super) inner: *mut T, | ||
pub (super) dst: *mut T, | ||
} | ||
|
||
impl<T> InPlaceDrop<T> { | ||
fn len(&self) -> usize { | ||
unsafe { self.dst.offset_from(self.inner) as usize } | ||
} | ||
} | ||
|
||
impl<T> Drop for InPlaceDrop<T> { | ||
#[inline] | ||
fn drop(&mut self) { | ||
unsafe { | ||
ptr::drop_in_place(slice::from_raw_parts_mut(self.inner, self.len())); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters