]> git.lizzy.rs Git - rust.git/commitdiff
Implement ExactSizeIterator for Args and ArgsOs
authorSimonas Kazlauskas <git@kazlauskas.me>
Mon, 16 Feb 2015 10:15:30 +0000 (12:15 +0200)
committerSimonas Kazlauskas <git@kazlauskas.me>
Mon, 16 Feb 2015 12:28:42 +0000 (14:28 +0200)
Fixes #22343

src/libstd/env.rs
src/libstd/sys/unix/os.rs
src/libstd/sys/windows/os.rs

index ea18838211f26b37b84f87ab94bc1695e57feda8..93dc3efe2c4fc7a1186811dc4e346c20db8fba85 100644 (file)
@@ -488,12 +488,20 @@ fn next(&mut self) -> Option<String> {
     fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() }
 }
 
+impl ExactSizeIterator for Args {
+    fn len(&self) -> usize { self.inner.len() }
+}
+
 impl Iterator for ArgsOs {
     type Item = OsString;
     fn next(&mut self) -> Option<OsString> { self.inner.next() }
     fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() }
 }
 
+impl ExactSizeIterator for ArgsOs {
+    fn len(&self) -> usize { self.inner.len() }
+}
+
 /// Returns the page size of the current architecture in bytes.
 pub fn page_size() -> usize {
     os_imp::page_size()
index 8a6ef17818a0956b57834360490c9445ea86d185..df03841276e9e483cf22444cd9e6cc4f1559f1f2 100644 (file)
@@ -247,6 +247,10 @@ fn next(&mut self) -> Option<OsString> { self.iter.next() }
     fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() }
 }
 
+impl ExactSizeIterator for Args {
+    fn len(&self) -> usize { self.iter.len() }
+}
+
 /// Returns the command line arguments
 ///
 /// Returns a list of the command line arguments.
index 7e684c5234141aad1e15762f0fa6503ba2996ae6..6aa1ac04ca9ae8b3328e255e443b21ff22921c79 100644 (file)
@@ -303,6 +303,10 @@ fn next(&mut self) -> Option<OsString> {
     fn size_hint(&self) -> (usize, Option<usize>) { self.range.size_hint() }
 }
 
+impl ExactSizeIterator for Args {
+    fn len(&self) -> usize { self.range.len() }
+}
+
 impl Drop for Args {
     fn drop(&mut self) {
         unsafe { c::LocalFree(self.cur as *mut c_void); }