specialize creating a Vec from a slice iterator where T: Copy
this was already implemented for Extend but not for FromIterator
This commit is contained in:
parent
dac0edfaaa
commit
290fe895ba
1 changed files with 14 additions and 0 deletions
|
@ -2299,6 +2299,20 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, T: 'a> SpecFrom<&'a T, slice::Iter<'a, T>> for Vec<T>
|
||||
where
|
||||
T: Copy,
|
||||
{
|
||||
// reuses the extend specialization for T: Copy
|
||||
fn from_iter(iterator: slice::Iter<'a, T>) -> Self {
|
||||
let mut vec = Vec::new();
|
||||
// must delegate to spec_extend() since extend() itself delegates
|
||||
// to spec_from for empty Vecs
|
||||
vec.spec_extend(iterator);
|
||||
vec
|
||||
}
|
||||
}
|
||||
|
||||
// Specialization trait used for Vec::extend
|
||||
trait SpecExtend<T, I> {
|
||||
fn spec_extend(&mut self, iter: I);
|
||||
|
|
Loading…
Add table
Reference in a new issue