| 
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::{env as env_imp, 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,36 @@ 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 `env::args` states that we will "panic during iteration if any  | 
 | 889 | +    // argument to the process is not valid Unicode".  | 
 | 890 | +    //  | 
 | 891 | +    // This offers two possible interpretations:  | 
 | 892 | +    // - a skipped argument is never encountered "during iteration"  | 
 | 893 | +    // - even a skipped argument is encountered "during iteration"  | 
 | 894 | +    //  | 
 | 895 | +    // As a panic can be observed, we err towards validating even skipped  | 
 | 896 | +    // arguments for now, though this is not explicitly promised by the API.  | 
881 | 897 | }  | 
882 | 898 | 
 
  | 
883 | 899 | #[stable(feature = "env", since = "1.0.0")]  | 
884 | 900 | impl ExactSizeIterator for Args {  | 
 | 901 | +    #[inline]  | 
885 | 902 |     fn len(&self) -> usize {  | 
886 | 903 |         self.inner.len()  | 
887 | 904 |     }  | 
 | 905 | + | 
 | 906 | +    #[inline]  | 
888 | 907 |     fn is_empty(&self) -> bool {  | 
889 | 908 |         self.inner.is_empty()  | 
890 | 909 |     }  | 
@@ -914,29 +933,81 @@ impl !Sync for ArgsOs {}  | 
914 | 933 | #[stable(feature = "env", since = "1.0.0")]  | 
915 | 934 | impl Iterator for ArgsOs {  | 
916 | 935 |     type Item = OsString;  | 
 | 936 | + | 
 | 937 | +    #[inline]  | 
917 | 938 |     fn next(&mut self) -> Option<OsString> {  | 
918 | 939 |         self.inner.next()  | 
919 | 940 |     }  | 
 | 941 | + | 
 | 942 | +    #[inline]  | 
 | 943 | +    fn next_chunk<const N: usize>(  | 
 | 944 | +        &mut self,  | 
 | 945 | +    ) -> Result<[OsString; N], array::IntoIter<OsString, N>> {  | 
 | 946 | +        self.inner.next_chunk()  | 
 | 947 | +    }  | 
 | 948 | + | 
 | 949 | +    #[inline]  | 
920 | 950 |     fn size_hint(&self) -> (usize, Option<usize>) {  | 
921 | 951 |         self.inner.size_hint()  | 
922 | 952 |     }  | 
 | 953 | + | 
 | 954 | +    #[inline]  | 
 | 955 | +    fn count(self) -> usize {  | 
 | 956 | +        self.inner.len()  | 
 | 957 | +    }  | 
 | 958 | + | 
 | 959 | +    #[inline]  | 
 | 960 | +    fn last(self) -> Option<OsString> {  | 
 | 961 | +        self.inner.last()  | 
 | 962 | +    }  | 
 | 963 | + | 
 | 964 | +    #[inline]  | 
 | 965 | +    fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {  | 
 | 966 | +        self.inner.advance_by(n)  | 
 | 967 | +    }  | 
 | 968 | + | 
 | 969 | +    #[inline]  | 
 | 970 | +    fn try_fold<B, F, R>(&mut self, init: B, f: F) -> R  | 
 | 971 | +    where  | 
 | 972 | +        F: FnMut(B, Self::Item) -> R,  | 
 | 973 | +        R: Try<Output = B>,  | 
 | 974 | +    {  | 
 | 975 | +        self.inner.try_fold(init, f)  | 
 | 976 | +    }  | 
 | 977 | + | 
 | 978 | +    #[inline]  | 
 | 979 | +    fn fold<B, F>(self, init: B, f: F) -> B  | 
 | 980 | +    where  | 
 | 981 | +        F: FnMut(B, Self::Item) -> B,  | 
 | 982 | +    {  | 
 | 983 | +        self.inner.fold(init, f)  | 
 | 984 | +    }  | 
923 | 985 | }  | 
924 | 986 | 
 
  | 
925 | 987 | #[stable(feature = "env", since = "1.0.0")]  | 
926 | 988 | impl ExactSizeIterator for ArgsOs {  | 
 | 989 | +    #[inline]  | 
927 | 990 |     fn len(&self) -> usize {  | 
928 | 991 |         self.inner.len()  | 
929 | 992 |     }  | 
 | 993 | + | 
 | 994 | +    #[inline]  | 
930 | 995 |     fn is_empty(&self) -> bool {  | 
931 | 996 |         self.inner.is_empty()  | 
932 | 997 |     }  | 
933 | 998 | }  | 
934 | 999 | 
 
  | 
935 | 1000 | #[stable(feature = "env_iterators", since = "1.12.0")]  | 
936 | 1001 | impl DoubleEndedIterator for ArgsOs {  | 
 | 1002 | +    #[inline]  | 
937 | 1003 |     fn next_back(&mut self) -> Option<OsString> {  | 
938 | 1004 |         self.inner.next_back()  | 
939 | 1005 |     }  | 
 | 1006 | + | 
 | 1007 | +    #[inline]  | 
 | 1008 | +    fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {  | 
 | 1009 | +        self.inner.advance_back_by(n)  | 
 | 1010 | +    }  | 
940 | 1011 | }  | 
941 | 1012 | 
 
  | 
942 | 1013 | #[stable(feature = "std_debug", since = "1.16.0")]  | 
 | 
0 commit comments