std/sys/env/
common.rs

1use crate::ffi::OsString;
2use crate::{fmt, vec};
3
4pub 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.
9pub struct EnvStrDebug<'a> {
10    slice: &'a [(OsString, OsString)],
11}
12
13impl fmt::Debug for EnvStrDebug<'_> {
14    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15        f.debug_list()
16            .entries(self.slice.iter().map(|(a, b)| (a.to_str().unwrap(), b.to_str().unwrap())))
17            .finish()
18    }
19}
20
21impl 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
31impl 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
37impl !Send for Env {}
38impl !Sync for Env {}
39
40impl 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}