spec_from_iter.rs - source
Description: Source of the Rust file `library/alloc/src/collections/vec_deque/spec_from_iter.rs`.

#
alloc/collections/vec_deque/
spec_from_iter.rs

    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
    21#[cfg(not(test))]
    22impl<T> SpecFromIter<T, crate::vec::IntoIter<T>> for VecDeque<T> {
    23    #[inline]
    24    fn spec_from_iter(iterator: crate::vec::IntoIter<T>) -> Self {
    25        iterator.into_vecdeque()
    26    }
    27}
    28
    29impl<T> SpecFromIter<T, IntoIter<T>> for VecDeque<T> {
    30    #[inline]
    31    fn spec_from_iter(iterator: IntoIter<T>) -> Self {
    32        iterator.into_vecdeque()
    33    }
    34}