FilePath

Struct FilePath 

Source
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.txt

The 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

Source

pub fn from_pathcomponents(path: Vec<PathComponent>) -> Self

Creates a new file path from path components.

§Arguments
  • path - The path components.
§Returns

The file path.

Source

pub fn from_realpath(path: PathBuf) -> Self

Creates a new file path from a real path.

§Arguments
  • path - The real path.
§Returns

The file path.

Source

pub fn join_realpath(&mut self, _path: PathBuf)

Source

pub fn extract_parent(&self, _temp_directory: &PathBuf)

Source

pub fn delete_parent(&self, _temp_directory: &PathBuf)

Source

pub fn resolve_file(&self) -> Result<PathBuf>

Resolves the file path to a single file.

§Returns

The resolved file path.

§Errors

Never

Source

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

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 Clone for FilePath

Source§

fn clone(&self) -> FilePath

Returns a duplicate 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 FilePath

Source§

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

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

impl<'de> Deserialize<'de> for FilePath

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 Display for FilePath

Source§

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

Formats the file path to a string.

Source§

impl Hash for FilePath

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 PartialEq for FilePath

Source§

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

Compares two file paths.

§Arguments
  • other - The other file path.
§Returns

Whether the file paths are equal.

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 Serialize for FilePath

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 FilePath

Auto Trait Implementations§

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> Same for T

Source§

type Output = T

Should always be Self
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

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