Rust library to convert a file path from/to slash path
path-slash is a tiny library to convert a file path (e.g. foo/bar, foo\bar or
C:\foo\bar) from/to slash path (e.g. foo/bar, C:/foo/bar).
On Unix-like OS, path separator is slash / by default. One may want to convert a Windows path. But on
Windows, file path separator \ needs to be replaced with slash / (and of course \s for escaping
characters should not be replaced).
Supported Rust version is 1.38.0 or later.
This package was inspired by Go's path/filepath.FromSlash
and path/filepath.ToSlash.
Usage
path_slash::PathExt, path_slash::PathBufExt and path_slash::CowExt traits are defined. By using them,
std::path::Path, std::path::PathBuf and std::borrow::Cow<'_, Path> gain some methods and associated functions.
PathExtPath::to_slash(&self) -> Option<Cow<'_, Path>>Path::to_slash_lossy(&self) -> Cow<'_, Path>
PathBufExtPathBuf::from_slash<S: AsRef<str>>(s: S) -> PathBufPathBuf::from_slash_lossy<S: AsRef<OsStr>>(s: S) -> PathBufPathBuf::from_backslash<S: AsRef<str>>(s: S) -> PathBufPathBuf::from_backslash_lossy<S: AsRef<OsStr>>(s: S) -> PathBufPathBuf::to_slash(&self) -> Option<Cow<'_, Path>>PathBuf::to_slash_lossy(&self) -> Cow<'_, Path>
CowExtCow::<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
Please read documents for more details.
Installation
Add path-slash to dependencies:
[]
= "0.x"