pub struct FilePath {
pub path: Vec<PathComponent>,
}Expand description
A file path. A file path specifies a target file. It may consist of multiple path components. Imagine the following file structure:
DIR stuff
\-- DIR more_stuff
\-- FILE archive.tar.gz
\-- FILE file_in_archive.txtThe file path to file_in_archive.txt would consist of the following path components:
stuff/more_stuff/archive.tar.gz(target: Archive)file_in_archive.txt(target: File)
The file path to archive.tar.gz would consist of the following path components:
stuff/more_stuff/archive.tar.gz(target: File)
§Fields
path- The path components.
§Examples
use std::path::PathBuf;
use backup_deduplicator::path::FilePath;
let path = FilePath::from_realpath(PathBuf::from("test.txt"));
Fields§
§path: Vec<PathComponent>Implementations§
Source§impl FilePath
impl FilePath
Sourcepub fn from_pathcomponents(path: Vec<PathComponent>) -> Self
pub fn from_pathcomponents(path: Vec<PathComponent>) -> Self
Sourcepub fn from_realpath(path: PathBuf) -> Self
pub fn from_realpath(path: PathBuf) -> Self
pub fn join_realpath(&mut self, _path: PathBuf)
pub fn extract_parent(&self, _temp_directory: &PathBuf)
pub fn delete_parent(&self, _temp_directory: &PathBuf)
Sourcepub fn resolve_file(&self) -> Result<PathBuf>
pub fn resolve_file(&self) -> Result<PathBuf>
Sourcepub fn child<Str: Into<OsString>>(&self, child_name: Str) -> FilePath
pub fn child<Str: Into<OsString>>(&self, child_name: Str) -> FilePath
Gets the child of where the file path points to.
§Arguments
child_name- The name of the child.
§Returns
The child file path.
§Example
use std::path::PathBuf;
use backup_deduplicator::path::FilePath;
let path = FilePath::from_realpath(PathBuf::from("test/"));
let child = path.child("child.txt");
assert_eq!(child.path[0].path, PathBuf::from("test/child.txt"));
assert_eq!(child.path.len(), 1);use std::path::PathBuf;
use backup_deduplicator::path::FilePath;
let path = FilePath::from_realpath(PathBuf::from("test/"));
let subpath = path.child("subdir").child("abc.txt");
assert_eq!(subpath.path[0].path, PathBuf::from("test/subdir/abc.txt"));
assert_eq!(subpath.path.len(), 1);Sourcepub fn parent(&self) -> Option<FilePath>
pub fn parent(&self) -> Option<FilePath>
Gets the parent of the file path.
§Returns
The parent file path. None if the file path has no parent.
§Example
use std::path::PathBuf;
use backup_deduplicator::path::FilePath;
let path = FilePath::from_realpath(PathBuf::from("test/abc/def.txt"));
let parent = path.parent().unwrap();
assert_eq!(parent.path[0].path, PathBuf::from("test/abc"));
// test/abc test/ "" None
let root = path.parent().unwrap().parent().unwrap().parent().unwrap().parent();
assert_eq!(root, None);Trait Implementations§
Source§impl<'de> Deserialize<'de> for FilePath
impl<'de> Deserialize<'de> for FilePath
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
impl Eq for FilePath
Auto Trait Implementations§
impl Freeze for FilePath
impl RefUnwindSafe for FilePath
impl Send for FilePath
impl Sync for FilePath
impl Unpin for FilePath
impl UnwindSafe for FilePath
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