]> git.lizzy.rs Git - rust.git/blob - library/alloc/src/collections/vec_deque/into_iter.rs
Auto merge of #88798 - sunfishcode:sunfishcode/windows-null-handles, r=joshtriplett
[rust.git] / library / alloc / src / collections / vec_deque / into_iter.rs
1 use core::fmt;
2 use core::iter::{FusedIterator, TrustedLen};
3
4 use crate::alloc::{Allocator, Global};
5
6 use super::VecDeque;
7
8 /// An owning iterator over the elements of a `VecDeque`.
9 ///
10 /// This `struct` is created by the [`into_iter`] method on [`VecDeque`]
11 /// (provided by the [`IntoIterator`] trait). See its documentation for more.
12 ///
13 /// [`into_iter`]: VecDeque::into_iter
14 /// [`IntoIterator`]: core::iter::IntoIterator
15 #[derive(Clone)]
16 #[stable(feature = "rust1", since = "1.0.0")]
17 pub struct IntoIter<
18     T,
19     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
20 > {
21     inner: VecDeque<T, A>,
22 }
23
24 impl<T, A: Allocator> IntoIter<T, A> {
25     pub(super) fn new(inner: VecDeque<T, A>) -> Self {
26         IntoIter { inner }
27     }
28 }
29
30 #[stable(feature = "collection_debug", since = "1.17.0")]
31 impl<T: fmt::Debug, A: Allocator> fmt::Debug for IntoIter<T, A> {
32     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33         f.debug_tuple("IntoIter").field(&self.inner).finish()
34     }
35 }
36
37 #[stable(feature = "rust1", since = "1.0.0")]
38 impl<T, A: Allocator> Iterator for IntoIter<T, A> {
39     type Item = T;
40
41     #[inline]
42     fn next(&mut self) -> Option<T> {
43         self.inner.pop_front()
44     }
45
46     #[inline]
47     fn size_hint(&self) -> (usize, Option<usize>) {
48         let len = self.inner.len();
49         (len, Some(len))
50     }
51 }
52
53 #[stable(feature = "rust1", since = "1.0.0")]
54 impl<T, A: Allocator> DoubleEndedIterator for IntoIter<T, A> {
55     #[inline]
56     fn next_back(&mut self) -> Option<T> {
57         self.inner.pop_back()
58     }
59 }
60
61 #[stable(feature = "rust1", since = "1.0.0")]
62 impl<T, A: Allocator> ExactSizeIterator for IntoIter<T, A> {
63     fn is_empty(&self) -> bool {
64         self.inner.is_empty()
65     }
66 }
67
68 #[stable(feature = "fused", since = "1.26.0")]
69 impl<T, A: Allocator> FusedIterator for IntoIter<T, A> {}
70
71 #[unstable(feature = "trusted_len", issue = "37572")]
72 unsafe impl<T, A: Allocator> TrustedLen for IntoIter<T, A> {}