Skip to content

Commit 16635f9

Browse files
committed
Override count, nth and last for Vars and VarsOs
Allows usage of optimized underlying implementations if any OS supports them.
1 parent 0c72f69 commit 16635f9

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/libstd/env.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,29 @@ impl Iterator for Vars {
142142
})
143143
}
144144
fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() }
145+
fn count(self) -> usize { self.inner.count() }
146+
fn nth(&mut self, n: usize) -> Option<(String, String)> {
147+
self.inner.nth(n).map(|(a, b)| {
148+
(a.into_string().unwrap(), b.into_string().unwrap())
149+
})
150+
}
151+
fn last(self) -> Option<(String, String)> {
152+
self.inner.last().map(|(a, b)| {
153+
(a.into_string().unwrap(), b.into_string().unwrap())
154+
})
155+
}
145156
}
146157

147158
#[stable(feature = "env", since = "1.0.0")]
148159
impl Iterator for VarsOs {
149160
type Item = (OsString, OsString);
150161
fn next(&mut self) -> Option<(OsString, OsString)> { self.inner.next() }
151162
fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() }
163+
fn count(self) -> usize { self.inner.count() }
164+
fn nth(&mut self, n: usize) -> Option<(OsString, OsString)> {
165+
self.inner.nth(n)
166+
}
167+
fn last(self) -> Option<(OsString, OsString)> { self.inner.last() }
152168
}
153169

154170
/// Fetches the environment variable `key` from the current process.

0 commit comments

Comments
 (0)