1 | use crate::ffi::OsString; |
2 | use crate::{fmt, vec}; |
3 | |
4 | pub struct Env { |
5 | iter: vec::IntoIter<(OsString, OsString)>, |
6 | } |
7 | |
8 | // FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt. |
9 | pub struct EnvStrDebug<'a> { |
10 | slice: &'a [(OsString, OsString)], |
11 | } |
12 | |
13 | impl fmt::Debug for EnvStrDebug<'_> { |
14 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
15 | f&mut DebugList<'_, '_>.debug_list() |
16 | .entries(self.slice.iter().map(|(a: &OsString, b: &OsString)| (a.to_str().unwrap(), b.to_str().unwrap()))) |
17 | .finish() |
18 | } |
19 | } |
20 | |
21 | impl Env { |
22 | pub(super) fn new(env: Vec<(OsString, OsString)>) -> Self { |
23 | Env { iter: env.into_iter() } |
24 | } |
25 | |
26 | pub fn str_debug(&self) -> impl fmt::Debug + '_ { |
27 | EnvStrDebug { slice: self.iter.as_slice() } |
28 | } |
29 | } |
30 | |
31 | impl fmt::Debug for Env { |
32 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
33 | f.debug_list().entries(self.iter.as_slice()).finish() |
34 | } |
35 | } |
36 | |
37 | impl !Send for Env {} |
38 | impl !Sync for Env {} |
39 | |
40 | impl Iterator for Env { |
41 | type Item = (OsString, OsString); |
42 | fn next(&mut self) -> Option<(OsString, OsString)> { |
43 | self.iter.next() |
44 | } |
45 | fn size_hint(&self) -> (usize, Option<usize>) { |
46 | self.iter.size_hint() |
47 | } |
48 | } |
49 | |