Skip to main content

PathExt

Trait PathExt 

Source
pub trait PathExt
where Self: AsRef<Path>,
{ // Required methods fn basename(&self) -> String; fn filename(&self) -> Cow<'_, str>; fn _filename(&self) -> Result<&str, StringError>; fn display_short(&self, _: &Path) -> String; fn len(&self) -> usize; fn is_hidden(&self) -> bool; fn abs(&self, _: impl AsRef<Path>) -> PathBuf; fn is_empty(&self) -> bool; fn normalize(&self) -> PathBuf; fn shell_quote(&self) -> Option<String>; }

Required Methods§

Source

fn basename(&self) -> String

Get the owned (lossy) basename of a valid path (for display purposes). Returns the original if path has no filename.

Source

fn filename(&self) -> Cow<'_, str>

Get the (lossy) basename of a valid path. Returns empty string + log::warn! if path has no filename.

Source

fn _filename(&self) -> Result<&str, StringError>

Convert to str, or provide useful error.

Source

fn display_short(&self, _: &Path) -> String

Source

fn len(&self) -> usize

Source

fn is_hidden(&self) -> bool

Robustly determine whether a file is hidden

Source

fn abs(&self, _: impl AsRef<Path>) -> PathBuf

Prepend base to current path then normalize.

§Example
use std::path::Path;
use cba::{bog::{BogOkExt, BogUnwrapExt}, bath::PathExt, bait::OptionExt};

let path = Path::new("");
path.abs(std::env::current_dir()._ebog().or_exit());
Source

fn is_empty(&self) -> bool

Source

fn normalize(&self) -> PathBuf

clean path logically (so that all components are Component::Normal)

Source

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

Quotes the path. Returns None if not Windows or Unix or not UTF-8.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

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