1 | use super::{IntoIter, VecDeque}; |
2 | |
3 | /// Specialization trait used for `VecDeque::from_iter` |
4 | pub(super) trait SpecFromIter<T, I> { |
5 | fn spec_from_iter(iter: I) -> Self; |
6 | } |
7 | |
8 | impl<T, I> SpecFromIter<T, I> for VecDeque<T> |
9 | where |
10 | I: Iterator<Item = T>, |
11 | { |
12 | #[track_caller ] |
13 | default fn spec_from_iter(iterator: I) -> Self { |
14 | // Since converting is O(1) now, just re-use the `Vec` logic for |
15 | // anything where we can't do something extra-special for `VecDeque`, |
16 | // especially as that could save us some monomorphization work |
17 | // if one uses the same iterators (like slice ones) with both. |
18 | crate::vec::Vec::from_iter(iterator).into() |
19 | } |
20 | } |
21 | |
22 | #[cfg (not(test))] |
23 | impl<T> SpecFromIter<T, crate::vec::IntoIter<T>> for VecDeque<T> { |
24 | #[inline ] |
25 | fn spec_from_iter(iterator: crate::vec::IntoIter<T>) -> Self { |
26 | iterator.into_vecdeque() |
27 | } |
28 | } |
29 | |
30 | impl<T> SpecFromIter<T, IntoIter<T>> for VecDeque<T> { |
31 | #[inline ] |
32 | fn spec_from_iter(iterator: IntoIter<T>) -> Self { |
33 | iterator.into_vecdeque() |
34 | } |
35 | } |
36 | |