pub struct RPath { /* private fields */ }Implementations§
Source§impl RPath
impl RPath
Sourcepub fn from<T: AsRef<Path>>(path: T) -> RPath
pub fn from<T: AsRef<Path>>(path: T) -> RPath
Creates a RPath from there: &str, Path, PathBuf
§Usage
use rustypath::RPath;
use std::path::{Path, PathBuf};
let rpath = RPath::from("/temp");
let rpath_from_path = RPath::from(Path::new("/temp"));
let rpath_from_pathbuf = RPath::from(PathBuf::from("/temp"));
assert_eq!(rpath, rpath_from_path);
assert_eq!(rpath, rpath_from_pathbuf);Sourcepub fn join<T: AsRef<Path>>(&self, p: T) -> RPath
pub fn join<T: AsRef<Path>>(&self, p: T) -> RPath
Joins an &str, Path or PathBuf to existing RPath
§Usage
use rustypath::RPath;
use std::path::{Path, PathBuf};
// join a "path_text" to `current_dir`
let rpath = RPath::pwd().join("path_text");
let rpath_ = RPath::pwd().join(Path::new("path_text"));
let rpath__ = RPath::pwd().join(PathBuf::from("path_text"));
assert_eq!(rpath, rpath_);
assert_eq!(rpath, rpath__);Sourcepub fn join_multiple<T: AsRef<Path>>(&mut self, ps: Vec<T>)
pub fn join_multiple<T: AsRef<Path>>(&mut self, ps: Vec<T>)
join multiple components to existing path
§Examples
use rustypath::RPath;
let rpath = RPath::from("/temp");
rpath.join_multiple(vec!["abc", "aaa"]);
assert_eq!(rpath, RPath::from("/temp/abc/aaa"));Sourcepub fn basename(&self) -> &str
pub fn basename(&self) -> &str
returns the basename of the path as &str
§Usage
use rustypath::RPath;
let rpath = RPath::from("/temp/abc.txt");
let basename: &str = rpath.basename();
assert_eq!(basename, "abc.txt");Sourcepub fn with_basename<S: AsRef<Path>>(&self, filename: S) -> RPath
pub fn with_basename<S: AsRef<Path>>(&self, filename: S) -> RPath
Creates a new RPath with a specified basename/filename
§Usage
use rustypath::RPath;
let rpath = RPath::from("/temp/abc.txt");
let new_rpath = RPath::from("/temp/xyz.txt");
let new_rpath_2 = rpath.with_basename("xyz.txt");
assert_eq!(new_rpath, new_rpath_2);Sourcepub fn dirname(&self) -> RPath
pub fn dirname(&self) -> RPath
Returns the parent of the RPath
§Usage
use rustypath::RPath;
let rpath = RPath::from("/temp/abc.txt");
let rpath_dir: RPath = rpath.dirname();
assert_eq!(rpath_dir, RPath::from("/temp"));Sourcepub fn with_dirname<S: AsRef<Path>>(&self, dirname: S) -> RPath
pub fn with_dirname<S: AsRef<Path>>(&self, dirname: S) -> RPath
Creates a new RPath with specified dirname/parent
§Usage
use rustypath::RPath;
let rpath = RPath::from("/temp/abc.txt");
let new = rpath.with_dirname("/temp/temp2");
assert_eq!(new, RPath::from("/temp/temp2/abc.txt"));Sourcepub fn extension(&self) -> &str
pub fn extension(&self) -> &str
Returns the extension of the basename if any.. else returns the basename
§Usage
use rustypath::RPath;
let rpath = RPath::from("/temp").join("abc.txt");
assert_eq!(rpath.extension(), "txt");
Sourcepub fn read_dir(&self) -> Result<ReadDir>
pub fn read_dir(&self) -> Result<ReadDir>
Returns an iterator over the entries within a directory.
The iterator will yield instances of io::Result<fs::DirEntry>. New errors may be encountered after an iterator is initially constructed.
use rustypath::RPath;
let rpath = RPath::from("/temp");
for entry in rpath.read_dir().expect("Failed to call read_dir") {
if let Ok(entry) = entry {
println!("{:?}", entry.path());
}
}Sourcepub fn pwd() -> RPath
pub fn pwd() -> RPath
Creates a RPath for the current directory.
§Usage
use rustypath::RPath;
use std::path::PathBuf;
// using RPath
let current_directory = RPath::pwd();
// using Conventional Method
let current_dir_using_conventional_method: PathBuf = match std::env::current_dir() {
Ok(value) => value,
Err(e) => {
eprintln!("Failed to get current dir: {}", e);
std::process::exit(1);
},
};
// Checking if it is correct
assert_eq!(current_directory.convert_to_pathbuf(), current_dir_using_conventional_method)Sourcepub fn gethomedir() -> RPath
pub fn gethomedir() -> RPath
Creates a RPath for the home directory
§Usage
use rustypath::RPath;
let home = RPath::gethomedir();
println!("{:?}", home);Sourcepub fn expand(&self) -> RPath
pub fn expand(&self) -> RPath
Returns the canonical, absolute form of the path with all intermediate components normalized and symbolic links resolved.
If it is already in canonical/absolute form, no changes are made.
NOTE: The RPath will only be expanded if that RPath exists.
§Usage
use rustypath::RPath;
let rpath = RPath::from("./src").expand();
let new_rpath = RPath::pwd().join("src");
assert_eq!(rpath, new_rpath);Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Invokes clear on the underlying PathBuf
§Usage
use rustypath::RPath;
let mut rpath = RPath::from("/temp/abc.txt");
rpath.clear();
assert_eq!(rpath, RPath::new());Sourcepub fn convert_to_pathbuf(&self) -> PathBuf
pub fn convert_to_pathbuf(&self) -> PathBuf
Converts RPath to PathBuf
§Usage
use rustypath::RPath;
use std::path::PathBuf;
let path: PathBuf = RPath::from("/temp/abc.txt").convert_to_pathbuf();
assert_eq!(path, PathBuf::from("/temp/abc.txt"));Sourcepub fn convert_to_string(&self) -> String
pub fn convert_to_string(&self) -> String
Converts RPath to String
§Usage
use rustypath::RPath;
let rpath = RPath::from("/temp/abc.txt");
assert_eq!(rpath.convert_to_string(), "/temp/abc.txt".to_string());Sourcepub fn exists(&self) -> bool
pub fn exists(&self) -> bool
returns true if the RPath exists else false
§Usage
use rustypath::RPath;
let rpath = RPath::from("/temp/abc.txt");
if rpath.exists() {
// do something
}Sourcepub fn is_dir(&self) -> bool
pub fn is_dir(&self) -> bool
returns true if the RPath is a directory else false
§Usage
use rustypath::RPath;
let rpath = RPath::from("/temp");
if rpath.is_dir(){
// do something
}Sourcepub fn is_absolute(&self) -> bool
pub fn is_absolute(&self) -> bool
returns true if the RPath is absolute else false
§Usage
use rustypath::RPath;
let rpath = RPath::from("/temp/abc.txt");
if rpath.is_absolute(){
// do something
}Sourcepub fn is_file(&self) -> bool
pub fn is_file(&self) -> bool
returns true if the RPath is a file else false
§Usage
use rustypath::RPath;
let rpath = RPath::from("/temp/abc.txt");
if rpath.is_file() {
// do something
}Sourcepub fn is_relative(&self) -> bool
pub fn is_relative(&self) -> bool
returns true if the RPath is a relative path else false
use rustypath::RPath;
let rpath = RPath::from("./temp");
if rpath.is_relative() {
// do something
}Sourcepub fn is_symlink(&self) -> bool
pub fn is_symlink(&self) -> bool
returns true if the RPath is a symlink else false
§Usage
use rustypath::RPath;
let rpath = RPath::from("/temp");
if rpath.is_symlink() {
// do something
}Sourcepub fn if_extension(&self, type: &str) -> bool
pub fn if_extension(&self, type: &str) -> bool
returns true if the RPath has the given extension. else false
§Usage
use rustypath::RPath;
let rpath = RPath::from("abc.txt");
if rpath.if_extension("txt") {
println!("This is a text file.");
}Trait Implementations§
Source§impl Ord for RPath
impl Ord for RPath
Source§impl PartialOrd for RPath
impl PartialOrd for RPath
impl Eq for RPath
impl StructuralPartialEq for RPath
Auto Trait Implementations§
impl Freeze for RPath
impl RefUnwindSafe for RPath
impl Send for RPath
impl Sync for RPath
impl Unpin for RPath
impl UnwindSafe for RPath
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)