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§
Sourcefn compact(&self) -> PathBuf
fn compact(&self) -> PathBuf
Compacts a given file path by replacing the user’s home directory
prefix with a tilde (~).
§Returns
- A
PathBufcontaining 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.
Returns a file’s extension or, if the file is hidden, its name without the leading dot
Sourcefn local_to_wsl(&self) -> Option<PathBuf>
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).
Sourcefn multiple_extensions(&self) -> Option<String>
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
Sourcefn try_shell_safe(&self) -> Result<String>
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