Skip to content

Commit 839311c

Browse files
committed
Implement ExactSizeIterator for Args and ArgsOs
Fixes #22343
1 parent c5db290 commit 839311c

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/libstd/env.rs

+8
Original file line numberDiff line numberDiff line change
@@ -488,12 +488,20 @@ impl Iterator for Args {
488488
fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() }
489489
}
490490

491+
impl ExactSizeIterator for Args {
492+
fn len(&self) -> usize { self.inner.len() }
493+
}
494+
491495
impl Iterator for ArgsOs {
492496
type Item = OsString;
493497
fn next(&mut self) -> Option<OsString> { self.inner.next() }
494498
fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() }
495499
}
496500

501+
impl ExactSizeIterator for ArgsOs {
502+
fn len(&self) -> usize { self.inner.len() }
503+
}
504+
497505
/// Returns the page size of the current architecture in bytes.
498506
pub fn page_size() -> usize {
499507
os_imp::page_size()

src/libstd/sys/unix/os.rs

+4
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ impl Iterator for Args {
247247
fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() }
248248
}
249249

250+
impl ExactSizeIterator for Args {
251+
fn len(&self) -> usize { self.iter.len() }
252+
}
253+
250254
/// Returns the command line arguments
251255
///
252256
/// Returns a list of the command line arguments.

src/libstd/sys/windows/os.rs

+4
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ impl Iterator for Args {
303303
fn size_hint(&self) -> (usize, Option<usize>) { self.range.size_hint() }
304304
}
305305

306+
impl ExactSizeIterator for Args {
307+
fn len(&self) -> usize { self.range.len() }
308+
}
309+
306310
impl Drop for Args {
307311
fn drop(&mut self) {
308312
unsafe { c::LocalFree(self.cur as *mut c_void); }

0 commit comments

Comments
 (0)