Skip to content

Commit

Permalink
Implement ExactSizeIterator for Args and ArgsOs
Browse files Browse the repository at this point in the history
Fixes #22343
  • Loading branch information
nagisa committed Feb 16, 2015
1 parent c5db290 commit 839311c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/libstd/env.rs
Expand Up @@ -488,12 +488,20 @@ impl Iterator for Args {
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()
Expand Down
4 changes: 4 additions & 0 deletions src/libstd/sys/unix/os.rs
Expand Up @@ -247,6 +247,10 @@ impl Iterator for Args {
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.
Expand Down
4 changes: 4 additions & 0 deletions src/libstd/sys/windows/os.rs
Expand Up @@ -303,6 +303,10 @@ impl Iterator for Args {
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); }
Expand Down

0 comments on commit 839311c

Please sign in to comment.