Struct RPath

Source
pub struct RPath { /* private fields */ }

Implementations§

Source§

impl RPath

Source

pub fn new() -> RPath

Allocates an empty RPath

§Usage
use rustypath::RPath;
 
let rpath = RPath::new();
Source

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);
Source

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__);
Source

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"));
Source

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");
Source

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);
Source

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"));
Source

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"));
Source

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");
 
Source

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());
    }
}
Source

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)
Source

pub fn gethomedir() -> RPath

Creates a RPath for the home directory

§Usage
use rustypath::RPath;
 
let home = RPath::gethomedir();
println!("{:?}", home);
Source

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);
Source

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());
Source

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"));
Source

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());
Source

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
}
Source

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
}
Source

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
}
Source

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
}
Source

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
}

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
}
Source

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 AsRef<RPath> for RPath

Source§

fn as_ref(&self) -> &RPath

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for RPath

Source§

fn clone(&self) -> RPath

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RPath

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for RPath

Source§

fn print(&self)

prints the RPath as a String

§Usage
use rustypath::{RPath, Display};
 
let rpath = RPath::from("/temp");
rpath.print();
Source§

fn print_default(&self)

Source§

impl Hash for RPath

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for RPath

Source§

fn cmp(&self, other: &RPath) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for RPath

Source§

fn eq(&self, other: &RPath) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for RPath

Source§

fn partial_cmp(&self, other: &RPath) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for RPath

Source§

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§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.