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
impl Path
sourcepub fn exists(&self) -> bool
pub fn exists(&self) -> bool
If the path does infact exist, the return value will be true, else, false
sourcepub fn basename(&self) -> String
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");sourcepub fn parent_path(&self) -> Self
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");sourcepub fn path_type(&self) -> PathType
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!"),
};sourcepub fn split_char() -> char
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() == '/');
}sourcepub fn add(&self, extra: &Self) -> Self
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");sourcepub fn add_str(&self, extra: &str) -> Self
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<'de> Deserialize<'de> for Path
impl<'de> Deserialize<'de> for Path
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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
impl PartialEq for Path
impl Eq for Path
impl StructuralEq for Path
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more