about summary refs log tree commit diff
path: root/src/libstd/process.rs
diff options
context:
space:
mode:
authorZack Weinberg <zackw@panix.com>2017-01-21 11:01:11 -0500
committerZack Weinberg <zackw@panix.com>2017-01-21 11:01:11 -0500
commit2580950fcd7c516ebd2fc090443b5406a18f77bb (patch)
tree4632a369d5d734c9c923aa3c2972ff27d52591e5 /src/libstd/process.rs
parentc74efddc89859b9ddfbdccf8ccb2fa9862a1681d (diff)
downloadrust-2580950fcd7c516ebd2fc090443b5406a18f77bb.tar.gz
rust-2580950fcd7c516ebd2fc090443b5406a18f77bb.zip
Generalize envs() and args() to iterators.
 * Command::envs() now takes anything that is IntoIterator<Item=(K, V)>
   where both K and V are AsRef<OsStr>.
 * Since we're not 100% sure that's the right signature, envs() is
   now marked unstable.  (You can use envs() with HashMap<str, str> but
   not Vec<(str, str)>, for instance.)
 * Update the test to match.

 * By analogy, args() now takes any IntoIterator<Item=S>, S: AsRef<OsStr>.
   This should be uncontroversial.
Diffstat (limited to 'src/libstd/process.rs')
-rw-r--r--src/libstd/process.rs15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/libstd/process.rs b/src/libstd/process.rs
index 1b1f2291826..d4dbbec1fee 100644
--- a/src/libstd/process.rs
+++ b/src/libstd/process.rs
@@ -345,7 +345,9 @@ impl Command {
     ///         .expect("ls command failed to start");
     /// ```
     #[stable(feature = "process", since = "1.0.0")]
-    pub fn args<S: AsRef<OsStr>>(&mut self, args: &[S]) -> &mut Command {
+    pub fn args<I, S>(&mut self, args: I) -> &mut Command
+        where I: IntoIterator<Item=S>, S: AsRef<OsStr>
+    {
         for arg in args {
             self.arg(arg.as_ref());
         }
@@ -385,8 +387,9 @@ impl Command {
     /// ```no_run
     /// use std::process::{Command, Stdio};
     /// use std::env;
+    /// use std::collections::HashMap;
     ///
-    /// let filtered_env : Vec<(String, String)> =
+    /// let filtered_env : HashMap<String, String> =
     ///     env::vars().filter(|&(ref k, _)|
     ///         k == "TERM" || k == "TZ" || k == "LANG" || k == "PATH"
     ///     ).collect();
@@ -399,11 +402,11 @@ impl Command {
     ///         .spawn()
     ///         .expect("printenv failed to start");
     /// ```
-    #[stable(feature = "command_envs", since = "1.16.0")]
-    pub fn envs<K, V>(&mut self, vars: &[(K, V)]) -> &mut Command
-        where K: AsRef<OsStr>, V: AsRef<OsStr>
+    #[unstable(feature = "command_envs", issue = "38526")]
+    pub fn envs<I, K, V>(&mut self, vars: I) -> &mut Command
+        where I: IntoIterator<Item=(K, V)>, K: AsRef<OsStr>, V: AsRef<OsStr>
     {
-        for &(ref key, ref val) in vars {
+        for (ref key, ref val) in vars {
             self.inner.env(key.as_ref(), val.as_ref());
         }
         self