Struct fspp::Path

source ·
pub struct Path { /* private fields */ }
Expand description

Path to a file or folder

When using Path::new(), the function will automatically convert forward/backward slashes depending on the OS

Implementations§

source§

impl Path

source

pub fn new(user_path: &str) -> Self

Create a new path

source

pub fn exists(&self) -> bool

If the path does infact exist, the return value will be true, else, false

source

pub fn to_string(&self) -> String

Convert path to string to be printed out or something

source

pub fn basename(&self) -> String

Get the base name of a path

Examples:
use fspp::*;

let path = Path::new("folder1/folder2/folder3/hello.txt");

assert!(path.basename() == "hello.txt");
source

pub fn parent_path(&self) -> Self

Get the parent path of a path

Examples:
use fspp::*;

let path = Path::new("folder1/folder2/folder3/hello.txt");

assert!(path.parent_path().to_string() == "folder1/folder2/folder3");
source

pub fn path_type(&self) -> PathType

Get the path type for a path

Examples:
use fspp::*;

let path = Path::new("hello.txt");

match path.path_type() {
    PathType::File => println!("hello.txt is a file!"),
    PathType::Directory => println!("hello.txt is... a directory!?"),
    PathType::Invalid => println!("hello.txt doesn't exist!"),
};
source

pub fn split_char() -> char

What is the filesystem split character for the current OS?

Examples:
use fspp::*;

if std::env::consts::OS == "windows" {
    assert!(Path::split_char() == '\\');
}

else {
    assert!(Path::split_char() == '/');
}
source

pub fn add(&self, extra: &Self) -> Self

Add path segments to an existing path

Examples:
use fspp::*;

let mut path = Path::new("folder1/folder2");
path = path.add(&Path::new("folder3/hello.txt")); // The function is smart enough to fill in the missing '/' at the beginning.

assert!(path.to_string() == "folder1/folder2/folder3/hello.txt");
source

pub fn add_str(&self, extra: &str) -> Self

Add path segments (&str) to an existing path

Examples:
use fspp::*;

let mut path = Path::new("folder1/folder2");
path = path.add_str("folder3/hello.txt"); // The function is smart enough to fill in the missing '/' at the beginning.

assert!(path.to_string() == "folder1/folder2/folder3/hello.txt");

Trait Implementations§

source§

impl Clone for Path

source§

fn clone(&self) -> Path

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 Path

source§

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

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

impl<'de> Deserialize<'de> for Path

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl PartialEq for Path

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Path

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for Path

source§

impl StructuralEq for Path

source§

impl StructuralPartialEq for Path

Auto Trait Implementations§

§

impl RefUnwindSafe for Path

§

impl Send for Path

§

impl Sync for Path

§

impl Unpin for Path

§

impl UnwindSafe for Path

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,