diff options
| author | Thalia Archibald <thalia@archibald.dev> | 2025-04-21 22:24:02 -0700 |
|---|---|---|
| committer | Thalia Archibald <thalia@archibald.dev> | 2025-04-21 22:38:22 -0700 |
| commit | 01485c9fe9a50b48fd4c78e7116dcaa2aeb87a40 (patch) | |
| tree | adcfc1020244397b7260945f2b6c78bf55f7f8b3 /library/std/src/sys/env/wasi.rs | |
| parent | 46952125661fa7bb6a016a6be4e03620da16a077 (diff) | |
| download | rust-01485c9fe9a50b48fd4c78e7116dcaa2aeb87a40.tar.gz rust-01485c9fe9a50b48fd4c78e7116dcaa2aeb87a40.zip | |
Unify owned `Env` types between platforms
Also, update the same pattern of reuse in `sys::args` to match.
Diffstat (limited to 'library/std/src/sys/env/wasi.rs')
| -rw-r--r-- | library/std/src/sys/env/wasi.rs | 50 |
1 files changed, 3 insertions, 47 deletions
diff --git a/library/std/src/sys/env/wasi.rs b/library/std/src/sys/env/wasi.rs index 6bdb2d5a547..3719f9db51e 100644 --- a/library/std/src/sys/env/wasi.rs +++ b/library/std/src/sys/env/wasi.rs @@ -1,55 +1,11 @@ use core::slice::memchr; +pub use super::common::Env; use crate::ffi::{CStr, OsStr, OsString}; +use crate::io; use crate::os::wasi::prelude::*; use crate::sys::common::small_c_string::run_with_cstr; use crate::sys::pal::os::{cvt, libc}; -use crate::{fmt, io, vec}; - -pub struct Env { - iter: vec::IntoIter<(OsString, OsString)>, -} - -// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt. -pub struct EnvStrDebug<'a> { - slice: &'a [(OsString, OsString)], -} - -impl fmt::Debug for EnvStrDebug<'_> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let Self { slice } = self; - f.debug_list() - .entries(slice.iter().map(|(a, b)| (a.to_str().unwrap(), b.to_str().unwrap()))) - .finish() - } -} - -impl Env { - pub fn str_debug(&self) -> impl fmt::Debug + '_ { - let Self { iter } = self; - EnvStrDebug { slice: iter.as_slice() } - } -} - -impl fmt::Debug for Env { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let Self { iter } = self; - f.debug_list().entries(iter.as_slice()).finish() - } -} - -impl !Send for Env {} -impl !Sync for Env {} - -impl Iterator for Env { - type Item = (OsString, OsString); - fn next(&mut self) -> Option<(OsString, OsString)> { - self.iter.next() - } - fn size_hint(&self) -> (usize, Option<usize>) { - self.iter.size_hint() - } -} cfg_if::cfg_if! { if #[cfg(target_feature = "atomics")] { @@ -91,7 +47,7 @@ pub fn env() -> Env { environ = environ.add(1); } } - return Env { iter: result.into_iter() }; + return Env::new(result); } // See src/libstd/sys/pal/unix/os.rs, same as that |
