|
12 | 12 |
|
13 | 13 | use crate::error::Error;
|
14 | 14 | use crate::ffi::{OsStr, OsString};
|
| 15 | +use crate::num::NonZero; |
| 16 | +use crate::ops::Try; |
15 | 17 | use crate::path::{Path, PathBuf};
|
16 | 18 | use crate::sys::os as os_imp;
|
17 |
| -use crate::{fmt, io, sys}; |
| 19 | +use crate::{array, fmt, io, sys}; |
18 | 20 |
|
19 | 21 | /// Returns the current working directory as a [`PathBuf`].
|
20 | 22 | ///
|
@@ -872,19 +874,28 @@ impl !Sync for Args {}
|
872 | 874 | #[stable(feature = "env", since = "1.0.0")]
|
873 | 875 | impl Iterator for Args {
|
874 | 876 | type Item = String;
|
| 877 | + |
875 | 878 | fn next(&mut self) -> Option<String> {
|
876 | 879 | self.inner.next().map(|s| s.into_string().unwrap())
|
877 | 880 | }
|
| 881 | + |
| 882 | + #[inline] |
878 | 883 | fn size_hint(&self) -> (usize, Option<usize>) {
|
879 | 884 | self.inner.size_hint()
|
880 | 885 | }
|
| 886 | + |
| 887 | + // Methods which skip args cannot simply delegate to the inner iterator, |
| 888 | + // because that would bypass UTF-8 validation. |
881 | 889 | }
|
882 | 890 |
|
883 | 891 | #[stable(feature = "env", since = "1.0.0")]
|
884 | 892 | impl ExactSizeIterator for Args {
|
| 893 | + #[inline] |
885 | 894 | fn len(&self) -> usize {
|
886 | 895 | self.inner.len()
|
887 | 896 | }
|
| 897 | + |
| 898 | + #[inline] |
888 | 899 | fn is_empty(&self) -> bool {
|
889 | 900 | self.inner.is_empty()
|
890 | 901 | }
|
@@ -914,29 +925,81 @@ impl !Sync for ArgsOs {}
|
914 | 925 | #[stable(feature = "env", since = "1.0.0")]
|
915 | 926 | impl Iterator for ArgsOs {
|
916 | 927 | type Item = OsString;
|
| 928 | + |
| 929 | + #[inline] |
917 | 930 | fn next(&mut self) -> Option<OsString> {
|
918 | 931 | self.inner.next()
|
919 | 932 | }
|
| 933 | + |
| 934 | + #[inline] |
| 935 | + fn next_chunk<const N: usize>( |
| 936 | + &mut self, |
| 937 | + ) -> Result<[OsString; N], array::IntoIter<OsString, N>> { |
| 938 | + self.inner.next_chunk() |
| 939 | + } |
| 940 | + |
| 941 | + #[inline] |
920 | 942 | fn size_hint(&self) -> (usize, Option<usize>) {
|
921 | 943 | self.inner.size_hint()
|
922 | 944 | }
|
| 945 | + |
| 946 | + #[inline] |
| 947 | + fn count(self) -> usize { |
| 948 | + self.inner.len() |
| 949 | + } |
| 950 | + |
| 951 | + #[inline] |
| 952 | + fn last(self) -> Option<OsString> { |
| 953 | + self.inner.last() |
| 954 | + } |
| 955 | + |
| 956 | + #[inline] |
| 957 | + fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>> { |
| 958 | + self.inner.advance_by(n) |
| 959 | + } |
| 960 | + |
| 961 | + #[inline] |
| 962 | + fn try_fold<B, F, R>(&mut self, init: B, f: F) -> R |
| 963 | + where |
| 964 | + F: FnMut(B, Self::Item) -> R, |
| 965 | + R: Try<Output = B>, |
| 966 | + { |
| 967 | + self.inner.try_fold(init, f) |
| 968 | + } |
| 969 | + |
| 970 | + #[inline] |
| 971 | + fn fold<B, F>(self, init: B, f: F) -> B |
| 972 | + where |
| 973 | + F: FnMut(B, Self::Item) -> B, |
| 974 | + { |
| 975 | + self.inner.fold(init, f) |
| 976 | + } |
923 | 977 | }
|
924 | 978 |
|
925 | 979 | #[stable(feature = "env", since = "1.0.0")]
|
926 | 980 | impl ExactSizeIterator for ArgsOs {
|
| 981 | + #[inline] |
927 | 982 | fn len(&self) -> usize {
|
928 | 983 | self.inner.len()
|
929 | 984 | }
|
| 985 | + |
| 986 | + #[inline] |
930 | 987 | fn is_empty(&self) -> bool {
|
931 | 988 | self.inner.is_empty()
|
932 | 989 | }
|
933 | 990 | }
|
934 | 991 |
|
935 | 992 | #[stable(feature = "env_iterators", since = "1.12.0")]
|
936 | 993 | impl DoubleEndedIterator for ArgsOs {
|
| 994 | + #[inline] |
937 | 995 | fn next_back(&mut self) -> Option<OsString> {
|
938 | 996 | self.inner.next_back()
|
939 | 997 | }
|
| 998 | + |
| 999 | + #[inline] |
| 1000 | + fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>> { |
| 1001 | + self.inner.advance_back_by(n) |
| 1002 | + } |
940 | 1003 | }
|
941 | 1004 |
|
942 | 1005 | #[stable(feature = "std_debug", since = "1.16.0")]
|
|
0 commit comments