From 2580950fcd7c516ebd2fc090443b5406a18f77bb Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Sat, 21 Jan 2017 11:01:11 -0500 Subject: Generalize envs() and args() to iterators. * Command::envs() now takes anything that is IntoIterator where both K and V are AsRef. * Since we're not 100% sure that's the right signature, envs() is now marked unstable. (You can use envs() with HashMap but not Vec<(str, str)>, for instance.) * Update the test to match. * By analogy, args() now takes any IntoIterator, S: AsRef. This should be uncontroversial. --- src/libstd/process.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/libstd/process.rs') 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>(&mut self, args: &[S]) -> &mut Command { + pub fn args(&mut self, args: I) -> &mut Command + where I: IntoIterator, S: AsRef + { 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 = /// 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(&mut self, vars: &[(K, V)]) -> &mut Command - where K: AsRef, V: AsRef + #[unstable(feature = "command_envs", issue = "38526")] + pub fn envs(&mut self, vars: I) -> &mut Command + where I: IntoIterator, K: AsRef, V: AsRef { - for &(ref key, ref val) in vars { + for (ref key, ref val) in vars { self.inner.env(key.as_ref(), val.as_ref()); } self -- cgit 1.4.1-3-g733a5