NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
crates.io · #1583 most downloaded on crates.io
Conversion to/from a file path from/to slash path
Last release 4 years ago
no release in 18 months
Release timing varies
gaps range from 2 weeks to 1.4 years
Most releases are documented
notes for 8 of 9 stable releases
Nothing withdrawn
no release was ever pulled
8 years old
9 releases · first in 2018
Added CowExt::to_slash and CowExt::to_slash_lossy . PathExt is no longer necessary to convert Cow<'a, Path> paths into slash paths.
CowExt::to_slash and CowExt::to_slash_lossy. PathExt is no longer necessary to convert Cow<'a, Path> paths into slash paths.rust-version field in Cargo.toml was added so that cargo can check the MSRV is met.BREAKING: to_slash and to_slash_lossy return Cow<'_, str> instead of String . Now heap allocation hapnens only when path separator is replaced. On Uni
to_slash and to_slash_lossy return Cow<'_, str> instead of String. Now heap allocation hapnens only when path separator is replaced. On Unix-like OS, almost all heap allocations can be removed by this change. Migrating from 0.1 to 0.2 is quite easy by adding Cow::into_owned call. If &str is sufficient for your use case, Cow::as_ref is better to avoid heap allocation. (#9)
use path_slash::PathExt as _;
// 0.1
let s: Option<String> = Path::new("/a/b").to_slash();
let s: String = Path::new("/a/b").to_slash_lossy();
// 0.2
let s: Option<String> = Path::new("/a/b").to_slash().map(Cow::into_owned);
let s: String = Path::new("/a/b").to_slash_lossy().into_owned();Path::to_slash(&self) -> Option<String>Path::to_slash_lossy(&self) -> StringPath::to_slash(&self) -> Option<Cow<'_, Path>>Path::to_slash_lossy(&self) -> Cow<'_, Path>// 0.1
#[cfg(target_os = "windows")]
assert_eq!(Path::new(r"\a\b\").to_slash_lossy(), "/a/b"); // Trailing slash is removed
#[cfg(not(target_os = "windows"))]
assert_eq!(Path::new("/a/b/").to_slash_lossy(), "/a/b/"); // Trailing slash is preserved
// 0.2
#[cfg(target_os = "windows")]
assert_eq!(Path::new(r"\a\b\").to_slash_lossy(), "/a/b/"); // Trailing slash is preserved
#[cfg(not(target_os = "windows"))]
assert_eq!(Path::new("/a/b/").to_slash_lossy(), "/a/b/"); // Trailing slash is preservedpath_slash::CowExt is added to extend Cow<'_, Path>. Its methods convert slash paths into Cow<'_, Path>. It is useful to avoid heap allocations as much as possible compared with PathBufExt. See the API document for more details. (#9)
use path_slash::CowExt as _;
let p = Cow::from_slash("foo/bar/piyo.txt"); // Heap allocation only happens on Windows
#[cfg(target_os = "windows")]
assert_eq!(p, Cow::Owned(PathBuf::from(r"foo\bar\piyo.txt")));
#[cfg(not(target_os = "windows"))]
assert_eq!(p, Cow::Borrowed(Path::new("foo/bar/piyo.txt")));CowExt are as follows:
Cow::<Path>::from_slash(s: &str) -> SelfCow::<Path>::from_slash_lossy(s: &OsStr) -> SelfCow::<Path>::from_backslash(s: &str) -> SelfCow::<Path>::from_backslash_lossy(s: &OsStr) -> SelfOne column per quarter.
to_slash and to_slash_lossy return Cow<'_, str> instead of String. Now heap allocation hapnens only when path separator is replaced. On Unix-like OS, almost all heap allocations can be removed by this change. Migrating from 0.1 to 0.2 is quite easy by adding Cow::into_owned call. If &str is sufficient for your use case, Cow::as_ref is better to avoid heap allocation. (#9)use path_slash::PathExt as _;
// 0.1
let s: Option<String> = Path::new("/a/b").to_slash();
let s: String = Path::new("/a/b").to_slash_lossy();
// 0.2
let s: Option<String> = Path::new("/a/b").to_slash().map(Cow::into_owned);
let s: String = Path::new("/a/b").to_slash_lossy().into_owned();
API changes are as follows:
Path::to_slash(&self) -> Option<String>Path::to_slash_lossy(&self) -> StringPath::to_slash(&self) -> Option<Cow<'_, Path>>Path::to_slash_lossy(&self) -> Cow<'_, Path>// 0.1
#[cfg(target_os = "windows")]
assert_eq!(Path::new(r"\a\b\").to_slash_lossy(), "/a/b"); // Trailing slash is removed
#[cfg(not(target_os = "windows"))]
assert_eq!(Path::new("/a/b/").to_slash_lossy(), "/a/b/"); // Trailing slash is preserved
// 0.2
#[cfg(target_os = "windows")]
assert_eq!(Path::new(r"\a\b\").to_slash_lossy(), "/a/b/"); // Trailing slash is preserved
#[cfg(not(target_os = "windows"))]
assert_eq!(Path::new("/a/b/").to_slash_lossy(), "/a/b/"); // Trailing slash is preserved
path_slash::CowExt is added to extend Cow<'_, Path>. Its methods convert slash paths into Cow<'_, Path>. It is useful to avoid heap allocations as much as possible compared with PathBufExt. See the API document for more details. (#9)use path_slash::CowExt as _;
let p = Cow::from_slash("foo/bar/piyo.txt"); // Heap allocation only happens on Windows
#[cfg(target_os = "windows")]
assert_eq!(p, Cow::Owned(PathBuf::from(r"foo\bar\piyo.txt")));
#[cfg(not(target_os = "windows"))]
assert_eq!(p, Cow::Borrowed(Path::new("foo/bar/piyo.txt")));
All methods added by importing CowExt are as follows:
Cow::<Path>::from_slash(s: &str) -> SelfCow::<Path>::from_slash_lossy(s: &OsStr) -> SelfCow::<Path>::from_backslash(s: &str) -> SelfCow::<Path>::from_backslash_lossy(s: &OsStr) -> Self[Changes][v0.2.0]
<a name="v0.1.5"></a>
Add new APIs to convert backslash paths to PathBuf . ( #8 , thanks @picobyte )
PathBuf. (#8, thanks @picobyte)
PathBuf::from_backslash converts &str into PathBuf with replacing \ on non-Windows OSPathBuf::from_backslash_lossy converts &OsStr into PathBuf with replacing \ on non-Windows OS[Changes][v0.1.5]
<a name="v0.1.4"></a>
Fix a final letter of paths with some verbatim prefixes was removed
[Changes][v0.1.4]
<a name="v0.1.3"></a>
Fix documentation
Fix: Root path separator was doubled when the path contains Windows driver letter. For example, when C:/foo was given, to_slash converted it to C:\\fo
C:/foo was given, to_slash converted it to C:\\foo. In this version it converts it to C:\foo correctly.to_slash() method.C:/foo was given, to_slash converted it to C:\\foo. In this version it converts it to C:\foo correctly.to_slash() method.<!-- Generated by https://github.com/rhysd/changelog-from-release -->
(cargo-release) version 0.1.1
(cargo-release) version 0.1.1
(cargo-release) version 0.1.0
(cargo-release) version 0.1.0
Nothing published for this version
Your coding agent can read these notes before it upgrades. Set up the MCP server →