2 use core::iter::{FusedIterator, TrustedLen, TrustedRandomAccess};
6 /// An owning iterator over the elements of a `VecDeque`.
8 /// This `struct` is created by the [`into_iter`] method on [`VecDeque`]
9 /// (provided by the `IntoIterator` trait). See its documentation for more.
11 /// [`into_iter`]: VecDeque::into_iter
13 #[stable(feature = "rust1", since = "1.0.0")]
14 pub struct IntoIter<T> {
15 pub(crate) inner: VecDeque<T>,
18 #[stable(feature = "collection_debug", since = "1.17.0")]
19 impl<T: fmt::Debug> fmt::Debug for IntoIter<T> {
20 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21 f.debug_tuple("IntoIter").field(&self.inner).finish()
25 #[stable(feature = "rust1", since = "1.0.0")]
26 impl<T> Iterator for IntoIter<T> {
30 fn next(&mut self) -> Option<T> {
31 self.inner.pop_front()
35 fn size_hint(&self) -> (usize, Option<usize>) {
36 let len = self.inner.len();
41 unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
43 Self: TrustedRandomAccess,
45 // Safety: The TrustedRandomAccess contract requires that callers only pass an index
47 // Additionally Self: TrustedRandomAccess is only implemented for T: Copy which means even
48 // multiple repeated reads of the same index would be safe and the
49 // values are !Drop, thus won't suffer from double drops.
51 let idx = self.inner.wrap_add(self.inner.tail, idx);
52 self.inner.buffer_read(idx)
57 #[stable(feature = "rust1", since = "1.0.0")]
58 impl<T> DoubleEndedIterator for IntoIter<T> {
60 fn next_back(&mut self) -> Option<T> {
65 #[stable(feature = "rust1", since = "1.0.0")]
66 impl<T> ExactSizeIterator for IntoIter<T> {
67 fn is_empty(&self) -> bool {
72 #[stable(feature = "fused", since = "1.26.0")]
73 impl<T> FusedIterator for IntoIter<T> {}
75 #[unstable(feature = "trusted_len", issue = "37572")]
76 unsafe impl<T> TrustedLen for IntoIter<T> {}
79 #[unstable(feature = "trusted_random_access", issue = "none")]
80 // T: Copy as approximation for !Drop since get_unchecked does not update the pointers
81 // and thus we can't implement drop-handling
82 unsafe impl<T> TrustedRandomAccess for IntoIter<T>
86 const MAY_HAVE_SIDE_EFFECT: bool = false;