Skip to content
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
21 changes: 16 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ impl<T> ThinVec<T> {
self.extend(other.drain(..))
}

pub fn drain<R>(&mut self, range: R) -> Drain<T>
pub fn drain<R>(&mut self, range: R) -> Drain<'_, T>
where
R: RangeBounds<usize>,
{
Expand Down Expand Up @@ -1118,6 +1118,7 @@ impl<T> AsRef<[T]> for ThinVec<T> {
}

impl<T> Extend<T> for ThinVec<T> {
#[inline]
fn extend<I>(&mut self, iter: I)
where
I: IntoIterator<Item = T>,
Expand All @@ -1131,7 +1132,7 @@ impl<T> Extend<T> for ThinVec<T> {
}

impl<T: fmt::Debug> fmt::Debug for ThinVec<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&**self, f)
}
}
Expand Down Expand Up @@ -1266,8 +1267,18 @@ where
T: Clone,
{
fn clone(&self) -> ThinVec<T> {
let mut new_vec = ThinVec::with_capacity(self.len());
new_vec.extend(self.iter().cloned());
let len = self.len();
let mut new_vec = ThinVec::<T>::with_capacity(len);
let mut data_raw = new_vec.data_raw();
for x in self.iter() {
unsafe {
ptr::write(data_raw, x.clone());
data_raw = data_raw.add(1);
}
}
unsafe {
new_vec.set_len(len); // could be the singleton
}
new_vec
}
}
Expand All @@ -1292,7 +1303,7 @@ pub struct IntoIter<T> {
start: usize,
}

pub struct Drain<'a, T: 'a> {
pub struct Drain<'a, T> {
iter: IterMut<'a, T>,
vec: *mut ThinVec<T>,
end: usize,
Expand Down