Skip to content

Commit aa68cbb

Browse files
committed
re-use vars_os in vars
1 parent f9d1c3e commit aa68cbb

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/lib.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -685,14 +685,12 @@ 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().into_iter().map(|(k, v)| (os_str_to_string(k), os_str_to_string(v))).collect()
696694
}
697695
}
698696

0 commit comments

Comments
 (0)