PathMod

Trait PathMod 

Source
pub trait PathMod {
    // Required methods
    fn is_dot(&self) -> bool;
    fn last_component(&self) -> Option<PathBuf>;
    fn first_component(&self) -> Option<PathBuf>;
    fn as_str(&self) -> &str;
    fn as_string(&self) -> String;
}
Expand description

Adds some useful functions for manipulating and retrieving information from paths

Required Methods§

Source

fn is_dot(&self) -> bool

Returns true if the path’s file name starts with a “.”

§Example
use rpf::PathMod;
use std::path::Path;

let path = Path::new("/test/dot/.dotfile");
assert_eq!(path.is_dot(), true);
Source

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

Returns a PathBuf of &self’s last component

§Example
use rpf::PathMod;
use std::path::PathBuf;

let path = PathBuf::from("/tmp/test/mod");
let last = path.last_component().unwrap();
assert_eq!(last, PathBuf::from("mod"));
Source

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

Returns a PathBuf of &self’s first component

§Example
use rpf::PathMod;
use std::path::PathBuf;

let path = PathBuf::from("/tmp/test/mod");
let first = path.first_component().unwrap();
assert_eq!(first, PathBuf::from("/"));
Source

fn as_str(&self) -> &str

Returns a &str for a path, returns a blank string if unable to get a string for the path

§Example
use rpf::PathMod;
use std::path::PathBuf;

let path = PathBuf::from("/usr/share");
let path_str = &path.as_str();
assert_eq!(path_str, &"/usr/share");
Source

fn as_string(&self) -> String

Returns a String for a path, returns an empty string if unable to get a string for a path

§Example
use rpf::PathMod;
use std::path::PathBuf;

let path_string = PathBuf::from("/var/log/test").as_string();
assert_eq!(path_string, "/var/log/test".to_string());

Implementations on Foreign Types§

Source§

impl PathMod for Path

Source§

impl PathMod for PathBuf

Implementors§