Skip to content

Commit

Permalink
fix document for from_backslash and from_backslash_lossy
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Jun 29, 2022
1 parent 759321a commit a5b6ce0
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,9 @@ impl PathBufExt for PathBuf {
PathBuf::from(s)
}

/// Convert the backslash path (path separated with '\') to [`std::path::PathBuf`].
/// Convert the backslash path (path separated with '\\') to [`std::path::PathBuf`].
///
/// Any '\' in the slash path is replaced with the file path separator.
/// Any '\\' in the slash path is replaced with the file path separator.
/// The replacements only happen on non-Windows.
#[cfg(not(target_os = "windows"))]
fn from_backslash<S: AsRef<str>>(s: S) -> Self {
Expand All @@ -334,19 +334,26 @@ impl PathBufExt for PathBuf {
PathBuf::from(s)
}

/// Convert the backslash path (path separated with '\\') to [`std::path::PathBuf`].
///
/// Any '\\' in the slash path is replaced with the file path separator.
/// The replacements only happen on non-Windows.
#[cfg(target_os = "windows")]
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`].
/// Convert the backslash path (path separated with '\\') to [`std::path::PathBuf`].
///
/// Any '\' in the slash path is replaced with the file path separator.
/// 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 {
s.as_ref().to_string_lossy().replace('\\', "/").into()
}

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

0 comments on commit a5b6ce0

Please sign in to comment.