Skip to content

Commit

Permalink
re-use vars_os in vars
Browse files Browse the repository at this point in the history
  • Loading branch information
bzm3r committed Jan 22, 2024
1 parent f9d1c3e commit aa68cbb
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,14 +685,12 @@ impl Shell {
/// If this is not desired, consider using
/// [`Shell::vars_os`](Self::vars_os).
pub fn vars(&self) -> Vec<(String, String)> {
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
#[inline]
fn os_str_to_string(os_str: OsString) -> String {
os_str.to_str().unwrap().to_string()
}
// re-use functionality from `Self::vars_os` to reduce code repetition
self.vars_os().into_iter().map(|(k, v)| (os_str_to_string(k), os_str_to_string(v))).collect()
}
}

Expand Down

0 comments on commit aa68cbb

Please sign in to comment.