[][src]Trait path_slash::PathExt

pub trait PathExt {
    pub fn to_slash(&self) -> Option<String>;
pub fn to_slash_lossy(&self) -> String; }

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

pub fn to_slash(&self) -> Option<String>[src]

pub fn to_slash_lossy(&self) -> String[src]

Loading content...

Implementations on Foreign Types

impl PathExt for Path[src]

pub 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());

pub 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(str::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()));
Loading content...

Implementors

Loading content...