[−][src]Trait path_slash::PathExt
Trait to extend std::path::Path.
use path_slash::PathExt; assert_eq!( std::path::Path::new("foo").to_slash(), Some("foo".to_string()), );
Required methods
fn to_slash(&self) -> Option<String>
fn to_slash_lossy(&self) -> String
Implementations on Foreign Types
impl PathExt for Path
[src]
impl PathExt for Path
fn to_slash_lossy(&self) -> String | [src] |
Convert the file path into slash path as UTF-8 string.
Any file path separators in the file path is replaced with '/'. Any non-Unicode sequences are replaced with U+FFFD.
On non-Windows OS, it is equivalent to to_string_lossy().to_string()
use std::path::Path; use path_slash::PathExt; #[cfg(target_os = "windows")] let s = Path::new(r"foo\bar\piyo.txt"); #[cfg(not(target_os = "windows"))] let s = Path::new("foo/bar/piyo.txt"); assert_eq!(s.to_slash_lossy(), "foo/bar/piyo.txt".to_string());
fn to_slash(&self) -> Option<String> | [src] |
Convert the file path into slash path as UTF-8 string.
Any file path separators in the file path is replaced with '/'. When the path contains non-Unicode sequence, this method returns None.
On non-Windows OS, it is equivalent to .to_str().map(std::to_string())
use std::path::Path; use path_slash::PathExt; #[cfg(target_os = "windows")] let s = Path::new(r"foo\bar\piyo.txt"); #[cfg(not(target_os = "windows"))] let s = Path::new("foo/bar/piyo.txt"); assert_eq!(s.to_slash(), Some("foo/bar/piyo.txt".to_string()));