diff --git a/src/lib.rs b/src/lib.rs index 026c945..0f1dd11 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -667,7 +667,10 @@ impl Shell { /// /// The returned hash map contains a snapshot of the process’s environment variables at the time of this invocation. Modifications to environment variables afterwards will not be reflected in the returned iterator. pub fn vars_os(&self) -> Vec<(OsString, OsString)> { - Vec::from_iter(self.env.borrow().iter().map(|(k, v)| (k.to_owned(), v.to_owned()))) + let mut vars = + Vec::from_iter(self.env.borrow().iter().map(|(k, v)| (k.to_owned(), v.to_owned()))); + vars.sort_unstable_by(|(a, _), (b, _)| a.cmp(b)); + vars } /// Returns the environment variables set for this shell. @@ -682,12 +685,14 @@ impl Shell { /// the environment is not valid unicode. If this is not desired, consider /// using [`Shell::vars_os`](Self::vars_os). pub fn vars(&self) -> Vec<(String, String)> { - Vec::from_iter( + let mut vars = Vec::from_iter( self.env .borrow() .iter() .map(|(k, v)| (k.to_str().unwrap().to_string(), v.to_str().unwrap().to_string())), - ) + ); + vars.sort_unstable_by(|(a, _), (b, _)| a.cmp(b)); + vars } }