PathExt

Trait PathExt 

Source
pub trait PathExt {
    // Required methods
    fn compact(&self) -> PathBuf;
    fn extension_or_hidden_file_name(&self) -> Option<&str>;
    fn local_to_wsl(&self) -> Option<PathBuf>;
    fn multiple_extensions(&self) -> Option<String>;
    fn try_shell_safe(&self) -> Result<String>;

    // Provided method
    fn try_from_bytes<'a>(bytes: &'a [u8]) -> Result<Self>
       where Self: From<&'a Path> { ... }
}

Required Methods§

Source

fn compact(&self) -> PathBuf

Compacts a given file path by replacing the user’s home directory prefix with a tilde (~).

§Returns
  • A PathBuf containing the compacted file path. If the input path does not have the user’s home directory prefix, or if we are not on Linux or macOS, the original path is returned unchanged.
Source

fn extension_or_hidden_file_name(&self) -> Option<&str>

Returns a file’s extension or, if the file is hidden, its name without the leading dot

Source

fn local_to_wsl(&self) -> Option<PathBuf>

Converts a local path to one that can be used inside of WSL. Returns None if the path cannot be converted into a WSL one (network share).

Source

fn multiple_extensions(&self) -> Option<String>

Returns a file’s “full” joined collection of extensions, in the case where a file does not just have a singular extension but instead has multiple (e.g File.tar.gz, Component.stories.tsx)

Will provide back the extensions joined together such as tar.gz or stories.tsx

Source

fn try_shell_safe(&self) -> Result<String>

Try to make a shell-safe representation of the path.

For Unix, the path is escaped to be safe for POSIX shells

Provided Methods§

Source

fn try_from_bytes<'a>(bytes: &'a [u8]) -> Result<Self>
where Self: From<&'a Path>,

Implementors§

Source§

impl<T: AsRef<Path>> PathExt for T