Skip to content

Commit 3a44b12

Browse files
committed
re-use vars_os in vars
1 parent 8ed74c4 commit 3a44b12

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/lib.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -685,14 +685,15 @@ impl Shell {
685685
/// If this is not desired, consider using
686686
/// [`Shell::vars_os`](Self::vars_os).
687687
pub fn vars(&self) -> Vec<(String, String)> {
688-
let mut vars = Vec::from_iter(
689-
self.env
690-
.borrow()
691-
.iter()
692-
.map(|(k, v)| (k.to_str().unwrap().to_string(), v.to_str().unwrap().to_string())),
693-
);
694-
vars.sort_unstable_by(|(a, _), (b, _)| a.cmp(b));
695-
vars
688+
#[inline]
689+
fn os_str_to_string(os_str: OsString) -> String {
690+
os_str.to_str().unwrap().to_string()
691+
}
692+
// re-use functionality from `Self::vars_os` to reduce code repetition
693+
self.vars_os()
694+
.into_iter()
695+
.map(|(k, v)| (os_str_to_string(k), os_str_to_string(v)))
696+
.collect()
696697
}
697698
}
698699

0 commit comments

Comments
 (0)