about summary refs log tree commit diff
path: root/library/std/src/sys_common
diff options
context:
space:
mode:
authorjoboet <jonasboettiger@icloud.com>2025-03-27 14:20:25 +0100
committerjoboet <jonasboettiger@icloud.com>2025-04-28 11:13:50 +0200
commit5f145689b1c0a313ee737de296a57d1479c18cb5 (patch)
tree3e211a503c830d0c0d0a3470b55dab6b3ffafb63 /library/std/src/sys_common
parent0134651fb81314870903e21b1bcbdd993d75b61a (diff)
downloadrust-5f145689b1c0a313ee737de296a57d1479c18cb5.tar.gz
rust-5f145689b1c0a313ee737de296a57d1479c18cb5.zip
std: get rid of `sys_common::process`
Move the public `CommandEnvs` into the `process` module (and make it a wrapper type for an internal iterator type) and everything else into `sys::process` as per #117276.
Diffstat (limited to 'library/std/src/sys_common')
-rw-r--r--library/std/src/sys_common/mod.rs1
-rw-r--r--library/std/src/sys_common/process.rs153
2 files changed, 0 insertions, 154 deletions
diff --git a/library/std/src/sys_common/mod.rs b/library/std/src/sys_common/mod.rs
index 2a5de7f6666..b7f4656fa37 100644
--- a/library/std/src/sys_common/mod.rs
+++ b/library/std/src/sys_common/mod.rs
@@ -20,7 +20,6 @@
 #[cfg(test)]
 mod tests;
 
-pub mod process;
 pub mod wstr;
 pub mod wtf8;
 
diff --git a/library/std/src/sys_common/process.rs b/library/std/src/sys_common/process.rs
deleted file mode 100644
index 9f61d69d858..00000000000
--- a/library/std/src/sys_common/process.rs
+++ /dev/null
@@ -1,153 +0,0 @@
-#![allow(dead_code)]
-#![unstable(feature = "process_internals", issue = "none")]
-
-use crate::collections::BTreeMap;
-use crate::ffi::{OsStr, OsString};
-use crate::sys::pipe::read2;
-use crate::sys::process::{EnvKey, ExitStatus, Process, StdioPipes};
-use crate::{env, fmt, io};
-
-// Stores a set of changes to an environment
-#[derive(Clone, Default)]
-pub struct CommandEnv {
-    clear: bool,
-    saw_path: bool,
-    vars: BTreeMap<EnvKey, Option<OsString>>,
-}
-
-impl fmt::Debug for CommandEnv {
-    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        let mut debug_command_env = f.debug_struct("CommandEnv");
-        debug_command_env.field("clear", &self.clear).field("vars", &self.vars);
-        debug_command_env.finish()
-    }
-}
-
-impl CommandEnv {
-    // Capture the current environment with these changes applied
-    pub fn capture(&self) -> BTreeMap<EnvKey, OsString> {
-        let mut result = BTreeMap::<EnvKey, OsString>::new();
-        if !self.clear {
-            for (k, v) in env::vars_os() {
-                result.insert(k.into(), v);
-            }
-        }
-        for (k, maybe_v) in &self.vars {
-            if let &Some(ref v) = maybe_v {
-                result.insert(k.clone(), v.clone());
-            } else {
-                result.remove(k);
-            }
-        }
-        result
-    }
-
-    pub fn is_unchanged(&self) -> bool {
-        !self.clear && self.vars.is_empty()
-    }
-
-    pub fn capture_if_changed(&self) -> Option<BTreeMap<EnvKey, OsString>> {
-        if self.is_unchanged() { None } else { Some(self.capture()) }
-    }
-
-    // The following functions build up changes
-    pub fn set(&mut self, key: &OsStr, value: &OsStr) {
-        let key = EnvKey::from(key);
-        self.maybe_saw_path(&key);
-        self.vars.insert(key, Some(value.to_owned()));
-    }
-
-    pub fn remove(&mut self, key: &OsStr) {
-        let key = EnvKey::from(key);
-        self.maybe_saw_path(&key);
-        if self.clear {
-            self.vars.remove(&key);
-        } else {
-            self.vars.insert(key, None);
-        }
-    }
-
-    pub fn clear(&mut self) {
-        self.clear = true;
-        self.vars.clear();
-    }
-
-    pub fn does_clear(&self) -> bool {
-        self.clear
-    }
-
-    pub fn have_changed_path(&self) -> bool {
-        self.saw_path || self.clear
-    }
-
-    fn maybe_saw_path(&mut self, key: &EnvKey) {
-        if !self.saw_path && key == "PATH" {
-            self.saw_path = true;
-        }
-    }
-
-    pub fn iter(&self) -> CommandEnvs<'_> {
-        let iter = self.vars.iter();
-        CommandEnvs { iter }
-    }
-}
-
-/// An iterator over the command environment variables.
-///
-/// This struct is created by
-/// [`Command::get_envs`][crate::process::Command::get_envs]. See its
-/// documentation for more.
-#[must_use = "iterators are lazy and do nothing unless consumed"]
-#[stable(feature = "command_access", since = "1.57.0")]
-#[derive(Debug)]
-pub struct CommandEnvs<'a> {
-    iter: crate::collections::btree_map::Iter<'a, EnvKey, Option<OsString>>,
-}
-
-#[stable(feature = "command_access", since = "1.57.0")]
-impl<'a> Iterator for CommandEnvs<'a> {
-    type Item = (&'a OsStr, Option<&'a OsStr>);
-    fn next(&mut self) -> Option<Self::Item> {
-        self.iter.next().map(|(key, value)| (key.as_ref(), value.as_deref()))
-    }
-    fn size_hint(&self) -> (usize, Option<usize>) {
-        self.iter.size_hint()
-    }
-}
-
-#[stable(feature = "command_access", since = "1.57.0")]
-impl<'a> ExactSizeIterator for CommandEnvs<'a> {
-    fn len(&self) -> usize {
-        self.iter.len()
-    }
-    fn is_empty(&self) -> bool {
-        self.iter.is_empty()
-    }
-}
-
-pub fn wait_with_output(
-    mut process: Process,
-    mut pipes: StdioPipes,
-) -> io::Result<(ExitStatus, Vec<u8>, Vec<u8>)> {
-    drop(pipes.stdin.take());
-
-    let (mut stdout, mut stderr) = (Vec::new(), Vec::new());
-    match (pipes.stdout.take(), pipes.stderr.take()) {
-        (None, None) => {}
-        (Some(out), None) => {
-            let res = out.read_to_end(&mut stdout);
-            res.unwrap();
-        }
-        (None, Some(err)) => {
-            let res = err.read_to_end(&mut stderr);
-            res.unwrap();
-        }
-        (Some(out), Some(err)) => {
-            let res = read2(out, &mut stdout, err, &mut stderr);
-            res.unwrap();
-        }
-    }
-
-    let status = process.wait()?;
-    Ok((status, stdout, stderr))
-}