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();
42 unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
44 Self: TrustedRandomAccess,
46 // Safety: The TrustedRandomAccess contract requires that callers only pass an index
48 // Additionally Self: TrustedRandomAccess is only implemented for T: Copy which means even
49 // multiple repeated reads of the same index would be safe and the
50 // values are !Drop, thus won't suffer from double drops.
52 let idx = self.inner.wrap_add(self.inner.tail, idx);
53 self.inner.buffer_read(idx)
58 #[stable(feature = "rust1", since = "1.0.0")]
59 impl<T> DoubleEndedIterator for IntoIter<T> {
61 fn next_back(&mut self) -> Option<T> {
66 #[stable(feature = "rust1", since = "1.0.0")]
67 impl<T> ExactSizeIterator for IntoIter<T> {
68 fn is_empty(&self) -> bool {
73 #[stable(feature = "fused", since = "1.26.0")]
74 impl<T> FusedIterator for IntoIter<T> {}
76 #[unstable(feature = "trusted_len", issue = "37572")]
77 unsafe impl<T> TrustedLen for IntoIter<T> {}
80 #[unstable(feature = "trusted_random_access", issue = "none")]
81 // T: Copy as approximation for !Drop since get_unchecked does not update the pointers
82 // and thus we can't implement drop-handling
83 unsafe impl<T> TrustedRandomAccess for IntoIter<T>
87 const MAY_HAVE_SIDE_EFFECT: bool = false;