]> git.proxmox.com Git - rustc.git/blob - library/alloc/src/collections/vec_deque/into_iter.rs
New upstream version 1.50.0+dfsg1
[rustc.git] / library / alloc / src / collections / vec_deque / into_iter.rs
1 use core::fmt;
2 use core::iter::FusedIterator;
3
4 use super::VecDeque;
5
6 /// An owning iterator over the elements of a `VecDeque`.
7 ///
8 /// This `struct` is created by the [`into_iter`] method on [`VecDeque`]
9 /// (provided by the `IntoIterator` trait). See its documentation for more.
10 ///
11 /// [`into_iter`]: VecDeque::into_iter
12 #[derive(Clone)]
13 #[stable(feature = "rust1", since = "1.0.0")]
14 pub struct IntoIter<T> {
15 pub(crate) inner: VecDeque<T>,
16 }
17
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()
22 }
23 }
24
25 #[stable(feature = "rust1", since = "1.0.0")]
26 impl<T> Iterator for IntoIter<T> {
27 type Item = T;
28
29 #[inline]
30 fn next(&mut self) -> Option<T> {
31 self.inner.pop_front()
32 }
33
34 #[inline]
35 fn size_hint(&self) -> (usize, Option<usize>) {
36 let len = self.inner.len();
37 (len, Some(len))
38 }
39 }
40
41 #[stable(feature = "rust1", since = "1.0.0")]
42 impl<T> DoubleEndedIterator for IntoIter<T> {
43 #[inline]
44 fn next_back(&mut self) -> Option<T> {
45 self.inner.pop_back()
46 }
47 }
48
49 #[stable(feature = "rust1", since = "1.0.0")]
50 impl<T> ExactSizeIterator for IntoIter<T> {
51 fn is_empty(&self) -> bool {
52 self.inner.is_empty()
53 }
54 }
55
56 #[stable(feature = "fused", since = "1.26.0")]
57 impl<T> FusedIterator for IntoIter<T> {}