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