Skip to content

Commit

Permalink
refactor redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Jun 29, 2022
1 parent a0704c4 commit 497a3b9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,13 @@ impl PathBufExt for PathBuf {
fn from_backslash<S: AsRef<str>>(s: S) -> Self {
PathBuf::from(s.as_ref())
}

/// Convert the backslash path (path separated with '\') to [`std::path::PathBuf`].
///
/// Any '\' in the slash path is replaced with the file path separator.
#[cfg(not(target_os = "windows"))]
fn from_backslash_lossy<S: AsRef<OsStr>>(s: S) -> Self {
PathBuf::from(s.as_ref().to_string_lossy().replace(r"\", "/").chars().as_str())
s.as_ref().to_string_lossy().replace('\\', "/").into()
}

#[cfg(target_os = "windows")]
Expand Down Expand Up @@ -407,7 +407,7 @@ impl PathBufExt for PathBuf {
/// ```
#[cfg(target_os = "windows")]
fn from_slash_lossy<S: AsRef<OsStr>>(s: S) -> Self {
Self::from_slash(s.as_ref().to_string_lossy().chars().as_str())
Self::from_slash(&s.as_ref().to_string_lossy())
}

/// Convert the file path into slash path as UTF-8 string.
Expand Down

0 comments on commit 497a3b9

Please sign in to comment.