Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit eb0af23

Browse files
committedApr 22, 2025
Unify owned Env types between platforms
Also, update the same pattern of reuse in `sys::args` to match.
1 parent 4b7ef7a commit eb0af23

File tree

15 files changed

+98
-348
lines changed

15 files changed

+98
-348
lines changed
 

‎std/src/sys/args/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
33
#![forbid(unsafe_op_in_unsafe_fn)]
44

5+
#[cfg(any(
6+
all(target_family = "unix", not(any(target_os = "espidf", target_os = "vita"))),
7+
target_family = "windows",
8+
target_os = "hermit",
9+
target_os = "uefi",
10+
target_os = "wasi",
11+
target_os = "xous",
12+
))]
13+
mod common;
14+
515
cfg_if::cfg_if! {
616
if #[cfg(any(
717
all(target_family = "unix", not(any(target_os = "espidf", target_os = "vita"))),

‎std/src/sys/args/uefi.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
use r_efi::protocols::loaded_image;
22

3+
pub use super::common::Args;
34
use crate::env::current_exe;
45
use crate::ffi::OsString;
56
use crate::iter::Iterator;
67
use crate::sys::pal::helpers;
78

8-
#[path = "common.rs"]
9-
mod common;
10-
pub use common::Args;
11-
129
pub fn args() -> Args {
1310
let lazy_current_exe = || Vec::from([current_exe().map(Into::into).unwrap_or_default()]);
1411

‎std/src/sys/args/unix.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@
55
66
#![allow(dead_code)] // runtime init functions not used during testing
77

8+
pub use super::common::Args;
89
use crate::ffi::CStr;
910
#[cfg(target_os = "hermit")]
1011
use crate::os::hermit::ffi::OsStringExt;
1112
#[cfg(not(target_os = "hermit"))]
1213
use crate::os::unix::ffi::OsStringExt;
1314

14-
#[path = "common.rs"]
15-
mod common;
16-
pub use common::Args;
17-
1815
/// One-time global initialization.
1916
pub unsafe fn init(argc: isize, argv: *const *const u8) {
2017
unsafe { imp::init(argc, argv) }

‎std/src/sys/args/wasi.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
#![forbid(unsafe_op_in_unsafe_fn)]
22

3+
pub use super::common::Args;
34
use crate::ffi::{CStr, OsStr, OsString};
45
use crate::os::wasi::ffi::OsStrExt;
56

6-
#[path = "common.rs"]
7-
mod common;
8-
pub use common::Args;
9-
107
/// Returns the command line arguments
118
pub fn args() -> Args {
129
Args::new(maybe_args().unwrap_or(Vec::new()))

‎std/src/sys/args/windows.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#[cfg(test)]
77
mod tests;
88

9+
pub use super::common::Args;
910
use crate::ffi::{OsStr, OsString};
1011
use crate::num::NonZero;
1112
use crate::os::windows::prelude::*;
@@ -18,10 +19,6 @@ use crate::sys_common::AsInner;
1819
use crate::sys_common::wstr::WStrUnits;
1920
use crate::{io, iter, ptr};
2021

21-
#[path = "common.rs"]
22-
mod common;
23-
pub use common::Args;
24-
2522
pub fn args() -> Args {
2623
// SAFETY: `GetCommandLineW` returns a pointer to a null terminated UTF-16
2724
// string so it's safe for `WStrUnits` to use.

‎std/src/sys/args/xous.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1+
pub use super::common::Args;
12
use crate::sys::pal::os::get_application_parameters;
23
use crate::sys::pal::os::params::ArgumentList;
34

4-
#[path = "common.rs"]
5-
mod common;
6-
pub use common::Args;
7-
85
pub fn args() -> Args {
96
let Some(params) = get_application_parameters() else {
107
return Args::new(vec![]);

‎std/src/sys/env/common.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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.debug_list()
16+
.entries(self.slice.iter().map(|(a, b)| (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+
}

‎std/src/sys/env/hermit.rs

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use core::slice::memchr;
22

3+
pub use super::common::Env;
34
use crate::collections::HashMap;
45
use crate::ffi::{CStr, OsStr, OsString, c_char};
6+
use crate::io;
57
use crate::os::hermit::ffi::OsStringExt;
68
use crate::sync::Mutex;
7-
use crate::{fmt, io, vec};
89

910
static ENV: Mutex<Option<HashMap<OsString, OsString>>> = Mutex::new(None);
1011

@@ -44,60 +45,15 @@ pub fn init(env: *const *const c_char) {
4445
}
4546
}
4647

47-
pub struct Env {
48-
iter: vec::IntoIter<(OsString, OsString)>,
49-
}
50-
51-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
52-
pub struct EnvStrDebug<'a> {
53-
slice: &'a [(OsString, OsString)],
54-
}
55-
56-
impl fmt::Debug for EnvStrDebug<'_> {
57-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
58-
let Self { slice } = self;
59-
f.debug_list()
60-
.entries(slice.iter().map(|(a, b)| (a.to_str().unwrap(), b.to_str().unwrap())))
61-
.finish()
62-
}
63-
}
64-
65-
impl Env {
66-
pub fn str_debug(&self) -> impl fmt::Debug + '_ {
67-
let Self { iter } = self;
68-
EnvStrDebug { slice: iter.as_slice() }
69-
}
70-
}
71-
72-
impl fmt::Debug for Env {
73-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
74-
let Self { iter } = self;
75-
f.debug_list().entries(iter.as_slice()).finish()
76-
}
77-
}
78-
79-
impl !Send for Env {}
80-
impl !Sync for Env {}
81-
82-
impl Iterator for Env {
83-
type Item = (OsString, OsString);
84-
fn next(&mut self) -> Option<(OsString, OsString)> {
85-
self.iter.next()
86-
}
87-
fn size_hint(&self) -> (usize, Option<usize>) {
88-
self.iter.size_hint()
89-
}
90-
}
91-
9248
/// Returns a vector of (variable, value) byte-vector pairs for all the
9349
/// environment variables of the current process.
9450
pub fn env() -> Env {
9551
let guard = ENV.lock().unwrap();
9652
let env = guard.as_ref().unwrap();
9753

98-
let result = env.iter().map(|(key, value)| (key.clone(), value.clone())).collect::<Vec<_>>();
54+
let result = env.iter().map(|(key, value)| (key.clone(), value.clone())).collect();
9955

100-
Env { iter: result.into_iter() }
56+
Env::new(result)
10157
}
10258

10359
pub fn getenv(k: &OsStr) -> Option<OsString> {

‎std/src/sys/env/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22
33
#![forbid(unsafe_op_in_unsafe_fn)]
44

5+
#[cfg(any(
6+
target_family = "unix",
7+
target_os = "hermit",
8+
all(target_vendor = "fortanix", target_env = "sgx"),
9+
target_os = "solid_asp3",
10+
target_os = "uefi",
11+
target_os = "wasi",
12+
target_os = "xous",
13+
))]
14+
mod common;
15+
516
cfg_if::cfg_if! {
617
if #[cfg(target_family = "unix")] {
718
mod unix;

‎std/src/sys/env/sgx.rs

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#![allow(fuzzy_provenance_casts)] // FIXME: this module systematically confuses pointers and integers
22

3+
pub use super::common::Env;
34
use crate::collections::HashMap;
45
use crate::ffi::{OsStr, OsString};
6+
use crate::io;
57
use crate::sync::atomic::{AtomicUsize, Ordering};
68
use crate::sync::{Mutex, Once};
7-
use crate::{fmt, io, vec};
89

910
// Specifying linkage/symbol name is solely to ensure a single instance between this crate and its unit tests
1011
#[cfg_attr(test, linkage = "available_externally")]
@@ -27,61 +28,13 @@ fn create_env_store() -> &'static EnvStore {
2728
unsafe { &*(ENV.load(Ordering::Relaxed) as *const EnvStore) }
2829
}
2930

30-
pub struct Env {
31-
iter: vec::IntoIter<(OsString, OsString)>,
32-
}
33-
34-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
35-
pub struct EnvStrDebug<'a> {
36-
slice: &'a [(OsString, OsString)],
37-
}
38-
39-
impl fmt::Debug for EnvStrDebug<'_> {
40-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41-
let Self { slice } = self;
42-
f.debug_list()
43-
.entries(slice.iter().map(|(a, b)| (a.to_str().unwrap(), b.to_str().unwrap())))
44-
.finish()
45-
}
46-
}
47-
48-
impl Env {
49-
pub fn str_debug(&self) -> impl fmt::Debug + '_ {
50-
let Self { iter } = self;
51-
EnvStrDebug { slice: iter.as_slice() }
52-
}
53-
}
54-
55-
impl fmt::Debug for Env {
56-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
57-
let Self { iter } = self;
58-
f.debug_list().entries(iter.as_slice()).finish()
59-
}
60-
}
61-
62-
impl !Send for Env {}
63-
impl !Sync for Env {}
64-
65-
impl Iterator for Env {
66-
type Item = (OsString, OsString);
67-
fn next(&mut self) -> Option<(OsString, OsString)> {
68-
self.iter.next()
69-
}
70-
fn size_hint(&self) -> (usize, Option<usize>) {
71-
self.iter.size_hint()
72-
}
73-
}
74-
7531
pub fn env() -> Env {
7632
let clone_to_vec = |map: &HashMap<OsString, OsString>| -> Vec<_> {
7733
map.iter().map(|(k, v)| (k.clone(), v.clone())).collect()
7834
};
7935

80-
let iter = get_env_store()
81-
.map(|env| clone_to_vec(&env.lock().unwrap()))
82-
.unwrap_or_default()
83-
.into_iter();
84-
Env { iter }
36+
let env = get_env_store().map(|env| clone_to_vec(&env.lock().unwrap())).unwrap_or_default();
37+
Env::new(env)
8538
}
8639

8740
pub fn getenv(k: &OsStr) -> Option<OsString> {

‎std/src/sys/env/solid.rs

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,19 @@
11
use core::slice::memchr;
22

3+
pub use super::common::Env;
34
use crate::ffi::{CStr, OsStr, OsString};
5+
use crate::io;
46
use crate::os::raw::{c_char, c_int};
57
use crate::os::solid::ffi::{OsStrExt, OsStringExt};
68
use crate::sync::{PoisonError, RwLock};
79
use crate::sys::common::small_c_string::run_with_cstr;
8-
use crate::{fmt, io, vec};
910

1011
static ENV_LOCK: RwLock<()> = RwLock::new(());
1112

1213
pub fn env_read_lock() -> impl Drop {
1314
ENV_LOCK.read().unwrap_or_else(PoisonError::into_inner)
1415
}
1516

16-
pub struct Env {
17-
iter: vec::IntoIter<(OsString, OsString)>,
18-
}
19-
20-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
21-
pub struct EnvStrDebug<'a> {
22-
slice: &'a [(OsString, OsString)],
23-
}
24-
25-
impl fmt::Debug for EnvStrDebug<'_> {
26-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27-
let Self { slice } = self;
28-
f.debug_list()
29-
.entries(slice.iter().map(|(a, b)| (a.to_str().unwrap(), b.to_str().unwrap())))
30-
.finish()
31-
}
32-
}
33-
34-
impl Env {
35-
pub fn str_debug(&self) -> impl fmt::Debug + '_ {
36-
let Self { iter } = self;
37-
EnvStrDebug { slice: iter.as_slice() }
38-
}
39-
}
40-
41-
impl fmt::Debug for Env {
42-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43-
let Self { iter } = self;
44-
f.debug_list().entries(iter.as_slice()).finish()
45-
}
46-
}
47-
48-
impl !Send for Env {}
49-
impl !Sync for Env {}
50-
51-
impl Iterator for Env {
52-
type Item = (OsString, OsString);
53-
fn next(&mut self) -> Option<(OsString, OsString)> {
54-
self.iter.next()
55-
}
56-
fn size_hint(&self) -> (usize, Option<usize>) {
57-
self.iter.size_hint()
58-
}
59-
}
60-
6117
/// Returns a vector of (variable, value) byte-vector pairs for all the
6218
/// environment variables of the current process.
6319
pub fn env() -> Env {
@@ -76,7 +32,7 @@ pub fn env() -> Env {
7632
environ = environ.add(1);
7733
}
7834
}
79-
return Env { iter: result.into_iter() };
35+
return Env::new(result);
8036
}
8137

8238
fn parse(input: &[u8]) -> Option<(OsString, OsString)> {

‎std/src/sys/env/uefi.rs

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,10 @@
1+
pub use super::common::Env;
12
use crate::ffi::{OsStr, OsString};
2-
use crate::{fmt, io};
3-
4-
pub struct EnvStrDebug<'a> {
5-
iter: &'a [(OsString, OsString)],
6-
}
7-
8-
impl fmt::Debug for EnvStrDebug<'_> {
9-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10-
let mut list = f.debug_list();
11-
for (a, b) in self.iter {
12-
list.entry(&(a.to_str().unwrap(), b.to_str().unwrap()));
13-
}
14-
list.finish()
15-
}
16-
}
17-
18-
pub struct Env(crate::vec::IntoIter<(OsString, OsString)>);
19-
20-
impl Env {
21-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
22-
pub fn str_debug(&self) -> impl fmt::Debug + '_ {
23-
EnvStrDebug { iter: self.0.as_slice() }
24-
}
25-
}
26-
27-
impl Iterator for Env {
28-
type Item = (OsString, OsString);
29-
30-
fn next(&mut self) -> Option<(OsString, OsString)> {
31-
self.0.next()
32-
}
33-
}
34-
35-
impl fmt::Debug for Env {
36-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37-
self.0.fmt(f)
38-
}
39-
}
3+
use crate::io;
404

415
pub fn env() -> Env {
426
let env = uefi_env::get_all().expect("not supported on this platform");
43-
Env(env.into_iter())
7+
Env::new(env)
448
}
459

4610
pub fn getenv(key: &OsStr) -> Option<OsString> {

‎std/src/sys/env/unix.rs

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,13 @@ use core::slice::memchr;
22

33
use libc::c_char;
44

5+
pub use super::common::Env;
56
use crate::ffi::{CStr, OsStr, OsString};
7+
use crate::io;
68
use crate::os::unix::prelude::*;
79
use crate::sync::{PoisonError, RwLock};
810
use crate::sys::common::small_c_string::run_with_cstr;
911
use crate::sys::cvt;
10-
use crate::{fmt, io, vec};
11-
12-
pub struct Env {
13-
iter: vec::IntoIter<(OsString, OsString)>,
14-
}
15-
16-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
17-
pub struct EnvStrDebug<'a> {
18-
slice: &'a [(OsString, OsString)],
19-
}
20-
21-
impl fmt::Debug for EnvStrDebug<'_> {
22-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23-
let Self { slice } = self;
24-
f.debug_list()
25-
.entries(slice.iter().map(|(a, b)| (a.to_str().unwrap(), b.to_str().unwrap())))
26-
.finish()
27-
}
28-
}
29-
30-
impl Env {
31-
pub fn str_debug(&self) -> impl fmt::Debug + '_ {
32-
let Self { iter } = self;
33-
EnvStrDebug { slice: iter.as_slice() }
34-
}
35-
}
36-
37-
impl fmt::Debug for Env {
38-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39-
let Self { iter } = self;
40-
f.debug_list().entries(iter.as_slice()).finish()
41-
}
42-
}
43-
44-
impl !Send for Env {}
45-
impl !Sync for Env {}
46-
47-
impl Iterator for Env {
48-
type Item = (OsString, OsString);
49-
fn next(&mut self) -> Option<(OsString, OsString)> {
50-
self.iter.next()
51-
}
52-
fn size_hint(&self) -> (usize, Option<usize>) {
53-
self.iter.size_hint()
54-
}
55-
}
5612

5713
// Use `_NSGetEnviron` on Apple platforms.
5814
//
@@ -112,7 +68,7 @@ pub fn env() -> Env {
11268
environ = environ.add(1);
11369
}
11470
}
115-
return Env { iter: result.into_iter() };
71+
return Env::new(result);
11672
}
11773

11874
fn parse(input: &[u8]) -> Option<(OsString, OsString)> {

‎std/src/sys/env/wasi.rs

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,11 @@
11
use core::slice::memchr;
22

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

5410
cfg_if::cfg_if! {
5511
if #[cfg(target_feature = "atomics")] {
@@ -91,7 +47,7 @@ pub fn env() -> Env {
9147
environ = environ.add(1);
9248
}
9349
}
94-
return Env { iter: result.into_iter() };
50+
return Env::new(result);
9551
}
9652

9753
// See src/libstd/sys/pal/unix/os.rs, same as that

‎std/src/sys/env/xous.rs

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
pub use super::common::Env;
12
use crate::collections::HashMap;
23
use crate::ffi::{OsStr, OsString};
4+
use crate::io;
35
use crate::sync::atomic::{AtomicUsize, Ordering};
46
use crate::sync::{Mutex, Once};
57
use crate::sys::pal::os::{get_application_parameters, params};
6-
use crate::{fmt, io, vec};
78

89
static ENV: AtomicUsize = AtomicUsize::new(0);
910
static ENV_INIT: Once = Once::new();
@@ -28,59 +29,13 @@ fn get_env_store() -> &'static EnvStore {
2829
unsafe { &*core::ptr::with_exposed_provenance::<EnvStore>(ENV.load(Ordering::Relaxed)) }
2930
}
3031

31-
pub struct Env {
32-
iter: vec::IntoIter<(OsString, OsString)>,
33-
}
34-
35-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
36-
pub struct EnvStrDebug<'a> {
37-
slice: &'a [(OsString, OsString)],
38-
}
39-
40-
impl fmt::Debug for EnvStrDebug<'_> {
41-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42-
let Self { slice } = self;
43-
f.debug_list()
44-
.entries(slice.iter().map(|(a, b)| (a.to_str().unwrap(), b.to_str().unwrap())))
45-
.finish()
46-
}
47-
}
48-
49-
impl Env {
50-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
51-
pub fn str_debug(&self) -> impl fmt::Debug + '_ {
52-
let Self { iter } = self;
53-
EnvStrDebug { slice: iter.as_slice() }
54-
}
55-
}
56-
57-
impl fmt::Debug for Env {
58-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
59-
let Self { iter } = self;
60-
f.debug_list().entries(iter.as_slice()).finish()
61-
}
62-
}
63-
64-
impl !Send for Env {}
65-
impl !Sync for Env {}
66-
67-
impl Iterator for Env {
68-
type Item = (OsString, OsString);
69-
fn next(&mut self) -> Option<(OsString, OsString)> {
70-
self.iter.next()
71-
}
72-
fn size_hint(&self) -> (usize, Option<usize>) {
73-
self.iter.size_hint()
74-
}
75-
}
76-
7732
pub fn env() -> Env {
7833
let clone_to_vec = |map: &HashMap<OsString, OsString>| -> Vec<_> {
7934
map.iter().map(|(k, v)| (k.clone(), v.clone())).collect()
8035
};
8136

82-
let iter = clone_to_vec(&*get_env_store().lock().unwrap()).into_iter();
83-
Env { iter }
37+
let env = clone_to_vec(&*get_env_store().lock().unwrap());
38+
Env::new(env)
8439
}
8540

8641
pub fn getenv(k: &OsStr) -> Option<OsString> {

0 commit comments

Comments
 (0)
Please sign in to comment.