1 | use crate::ffi::OsString; |
2 | use crate::num::NonZero; |
3 | use crate::ops::Try; |
4 | use crate::{array, fmt, vec}; |
5 | |
6 | pub struct Args { |
7 | iter: vec::IntoIter<OsString>, |
8 | } |
9 | |
10 | impl !Send for Args {} |
11 | impl !Sync for Args {} |
12 | |
13 | impl Args { |
14 | #[inline ] |
15 | pub(super) fn new(args: Vec<OsString>) -> Self { |
16 | Args { iter: args.into_iter() } |
17 | } |
18 | } |
19 | |
20 | impl fmt::Debug for Args { |
21 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
22 | self.iter.as_slice().fmt(f) |
23 | } |
24 | } |
25 | |
26 | impl Iterator for Args { |
27 | type Item = OsString; |
28 | |
29 | #[inline ] |
30 | fn next(&mut self) -> Option<OsString> { |
31 | self.iter.next() |
32 | } |
33 | |
34 | #[inline ] |
35 | fn next_chunk<const N: usize>( |
36 | &mut self, |
37 | ) -> Result<[OsString; N], array::IntoIter<OsString, N>> { |
38 | self.iter.next_chunk() |
39 | } |
40 | |
41 | #[inline ] |
42 | fn size_hint(&self) -> (usize, Option<usize>) { |
43 | self.iter.size_hint() |
44 | } |
45 | |
46 | #[inline ] |
47 | fn count(self) -> usize { |
48 | self.iter.len() |
49 | } |
50 | |
51 | #[inline ] |
52 | fn last(self) -> Option<OsString> { |
53 | self.iter.last() |
54 | } |
55 | |
56 | #[inline ] |
57 | fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>> { |
58 | self.iter.advance_by(n) |
59 | } |
60 | |
61 | #[inline ] |
62 | fn try_fold<B, F, R>(&mut self, init: B, f: F) -> R |
63 | where |
64 | F: FnMut(B, Self::Item) -> R, |
65 | R: Try<Output = B>, |
66 | { |
67 | self.iter.try_fold(init, f) |
68 | } |
69 | |
70 | #[inline ] |
71 | fn fold<B, F>(self, init: B, f: F) -> B |
72 | where |
73 | F: FnMut(B, Self::Item) -> B, |
74 | { |
75 | self.iter.fold(init, f) |
76 | } |
77 | } |
78 | |
79 | impl DoubleEndedIterator for Args { |
80 | #[inline ] |
81 | fn next_back(&mut self) -> Option<OsString> { |
82 | self.iter.next_back() |
83 | } |
84 | |
85 | #[inline ] |
86 | fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>> { |
87 | self.iter.advance_back_by(n) |
88 | } |
89 | } |
90 | |
91 | impl ExactSizeIterator for Args { |
92 | #[inline ] |
93 | fn len(&self) -> usize { |
94 | self.iter.len() |
95 | } |
96 | |
97 | #[inline ] |
98 | fn is_empty(&self) -> bool { |
99 | self.iter.is_empty() |
100 | } |
101 | } |
102 | |