path-slash
Conversion to/from a file path from/to slash path
0.2.1
35M downloads/mo
#1545 most downloaded on crates.io
rhysd/path-slash
What this package is like to depend on
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
0 releases in the last 12 months
see the full history below
Release timeline
9 releases · Dec 2018 to Aug 2022Releases
latest 9-
0.2.106 Aug 2022Release notes
Open source →- Added
CowExt::to_slashandCowExt::to_slash_lossy.PathExtis no longer necessary to convertCow<'a, Path>paths into slash paths. - Clarified minimum supported Rust version. Rust 1.38 or later is supported.
rust-versionfield inCargo.tomlwas added so thatcargocan check the MSRV is met. - Improved documents of trait methods. The documents were moved from implementations of the trait methods to definitions of them so that users can find out the documents more easily. Documents for implementations are folded by default, but definitions aren't.
Release notes
Open source →- Added
CowExt::to_slashandCow::to_slash_lossy.PathExtis no longer necessary to convertCow<'a, Path>paths into slash paths. - Clarified minimum supported Rust version. Rust 1.38 or later is supported.
rust-versionfield inCargo.tomlwas added so thatcargocan check the MSRV is met. - Improved documents of trait methods. The documents were moved from implementations of the trait methods to definitions of them so that users can find out the documents more easily. Documents for implementations are folded by default, but definitions aren't.
[Changes][v0.2.1]
<a name="v0.2.0"></a>
- Added
-
0.2.005 Jul 2022Release notes
Open source →- BREAKING:
to_slashandto_slash_lossyreturnCow<'_, str>instead ofString. 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 addingCow::into_ownedcall. If&stris sufficient for your use case,Cow::as_refis better to avoid heap allocation. (#9)API changes are as follows: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();
- 0.1.5
Path::to_slash(&self) -> Option<String>Path::to_slash_lossy(&self) -> String
- 0.2.0
Path::to_slash(&self) -> Option<Cow<'_, Path>>Path::to_slash_lossy(&self) -> Cow<'_, Path>
- 0.1.5
- BREAKING: Fix inconsistency on Windows and on Unix-like OS in terms of trailing slash in path. Now a trailing slash in path is always preserved. (#10)
// 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
- New API
path_slash::CowExtis added to extendCow<'_, Path>. Its methods convert slash paths intoCow<'_, Path>. It is useful to avoid heap allocations as much as possible compared withPathBufExt. See the API document for more details. (#9)All methods added by importinguse 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")));
CowExtare 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
- More tests are added. Now the line coverage is 100%.
- UTF-16 test cases for native encoding on Windows
- All error cases including broken UTF-8 and UTF-16 sequences
Release notes
Open source →- BREAKING:
to_slashandto_slash_lossyreturnCow<'_, str>instead ofString. 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 addingCow::into_ownedcall. If&stris sufficient for your use case,Cow::as_refis better to avoid heap allocation. (#9)
API changes are as follows: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();- 0.1.5
Path::to_slash(&self) -> Option<String>Path::to_slash_lossy(&self) -> String
- 0.2.0
Path::to_slash(&self) -> Option<Cow<'_, Path>>Path::to_slash_lossy(&self) -> Cow<'_, Path>
- 0.1.5
- BREAKING: Fix inconsistency on Windows and on Unix-like OS in terms of trailing slash in path. Now a trailing slash in path is always preserved. (#10)
// 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 - New API
path_slash::CowExtis added to extendCow<'_, Path>. Its methods convert slash paths intoCow<'_, Path>. It is useful to avoid heap allocations as much as possible compared withPathBufExt. See the API document for more details. (#9)
All methods added by importinguse 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")));CowExtare 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
- More tests are added. Now the line coverage is 100%.
- UTF-16 test cases for native encoding on Windows
- All error cases including broken UTF-8 and UTF-16 sequences
[Changes][v0.2.0]
<a name="v0.1.5"></a>
Release notes
Open source →- BREAKING:
to_slashandto_slash_lossyreturnCow<'_, str>instead ofString. 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 easy by addingCow::into_ownedcall. (#9)
API changes are as follows: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();- 0.1.5
Path::to_slash(&self) -> Option<String>Path::to_slash_lossy(&self) -> String
- 0.2.0
Path::to_slash(&self) -> Option<Cow<'_, Path>>Path::to_slash_lossy(&self) -> Cow<'_, Path>
- 0.1.5
- BREAKING: Fix inconsistency on Windows and on Unix-like OS in terms of trailing slash in path. Now a trailing slash in path is always preserved. (#10)
// 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(r"\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(r"\a\b\").to_slash_lossy(), "/a/b/"); // Trailing slash is preserved - New API
path_slash::CowExtis added to extendCow<'_, Path>. Methods to convert slash paths toCow<'_, Path>are available. It is useful to avoid heap allocation as much as possible comparing withPathBufExt. See the API document for more details. (#9)
All methods added by importinguse 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")));CowExtare 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
- More tests are added. Now the line coverage is 100%.
- UTF-16 test cases for native encoding on Windows
- All error cases including broken UTF-8 and UTF-16 sequences
[Changes][v0.2.0]
<a name="v0.1.5"></a>
- BREAKING:
-
0.1.529 Jun 2022Release notes
Open source →- Add new APIs to convert backslash paths to
PathBuf. (#8, thanks @picobyte)PathBuf::from_backslashconverts&strintoPathBufwith replacing\on non-Windows OSPathBuf::from_backslash_lossyconverts&OsStrintoPathBufwith replacing\on non-Windows OS
[Changes][v0.1.5]
<a name="v0.1.4"></a>
Release notes
Open source →- Add new APIs to convert backslash paths to
PathBuf. (#8, thanks @picobyte)PathBuf::from_backslashconverts&strintoPathBufwith replacing\on non-Windows OSPathBuf::from_backslashconverts&OsStrintoPathBufwith replacing\on non-Windows OS
[Changes][v0.1.5]
<a name="v0.1.4"></a>
- Add new APIs to convert backslash paths to
-
0.1.415 Jan 2021Release notes
Open source →- Fix a final letter of paths with some verbatim prefixes was removed (#5)
Release notes
Open source →- Fix a final letter of paths with some verbatim prefixes was removed (#5)
[Changes][v0.1.4]
<a name="v0.1.3"></a>
Release notes
Open source →- Fix a final letter of paths with some verbatim prefixes was removed (#5)
[Changes][v0.1.4]
<a name="v0.1.3"></a>
-
0.1.301 Jul 2020 -
0.1.216 Jun 2020Release notes
Open source →- Fix: Root path separator was doubled when the path contains Windows driver letter. For example, when
C:/foowas given,to_slashconverted it toC:\\foo. In this version it converts it toC:\foocorrectly. - Improve: Remove a redundant allocation at calling
to_slash()method.
Release notes
Open source →- Fix: Root path separator was doubled when the path contains Windows driver letter. For example, when
C:/foowas given,to_slashconverted it toC:\\foo. In this version it converts it toC:\foocorrectly. - Improve: Remove a redundant allocation at calling
to_slash()method.
<!-- Generated by https://github.com/rhysd/changelog-from-release -->
Release notes
Open source →- Fix: Root path separator was doubled when the path contains Windows driver letter. For example, when
C:/foowas given,to_slashconverted it toC:\\foo. In this version it converts it toC:\foocorrectly. - Improve: Remove a redundant allocation at calling
to_slash()method.
<!-- Generated by https://github.com/rhysd/changelog-from-release -->
- Fix: Root path separator was doubled when the path contains Windows driver letter. For example, when
-
0.1.112 Jan 2019 -
0.1.030 Dec 2018 -
0.0.130 Dec 2018Nothing published for this version