DirDescendant

Struct DirDescendant 

Source
pub struct DirDescendant<T, P: PathType + ?Sized = Path> { /* private fields */ }
Expand description

A single directory descendant, identified by its path relative to the ascendant.

It also stores the path relative to the “root.”

Implementations§

Source§

impl<T, P: PathType + ?Sized> DirDescendant<T, P>

Source

pub fn new( name: impl Into<P::PathSegmentOwned>, path: impl Into<P::OwnedPath>, path_relative_to_ascendant: impl Into<P::OwnedPath>, value: T, ) -> Self

Create a new directory descendant from its parts.

§Examples
use std::ffi::OsString;
use std::path::Path;
use std::path::PathBuf;
use dir_structure::dir_descendants::DirDescendant;

let descendant = DirDescendant::<_, Path>::new(
    "child".to_owned(),
    "root/a/b/child".to_owned(),
    "a/b/child".to_owned(),
    String::from("child_value"),
);
assert_eq!(descendant.name(), &OsString::from("child"));
assert_eq!(descendant.path(), &PathBuf::from("root/a/b/child"));
assert_eq!(descendant.path_relative_to_ascendant(), &PathBuf::from("a/b/child"));
assert_eq!(descendant.value(), &String::from("child_value"));
Source

pub fn name(&self) -> &P::PathSegmentOwned

Get the name of the directory descendant.

§Examples
use std::ffi::OsString;
use std::path::Path;
use dir_structure::dir_descendants::DirDescendant;

let descendant = DirDescendant::<_, Path>::new(
    "child",
    "root/a/b/child",
    "a/b/child",
    String::from("child_value"),
);
assert_eq!(descendant.name(), &OsString::from("child"));
Source

pub fn path(&self) -> &P

Get the path of the directory descendant.

§Examples
use std::path::PathBuf;
use std::path::Path;
use dir_structure::dir_descendants::DirDescendant;

let descendant = DirDescendant::<_, Path>::new(
    "child",
    "root/a/b/child",
    "a/b/child",
    String::from("child_value"),
);
assert_eq!(descendant.path(), &PathBuf::from("root/a/b/child"));
Source

pub fn path_relative_to_ascendant(&self) -> &P

Get the path relative to the ascendant.

§Examples
use std::path::PathBuf;
use std::path::Path;
use dir_structure::dir_descendants::DirDescendant;

let descendant = DirDescendant::<_, Path>::new(
    "child",
    "root/a/b/child",
    "a/b/child",
    String::from("child_value"),
);
assert_eq!(descendant.path_relative_to_ascendant(), &PathBuf::from("a/b/child"));
Source

pub fn value(&self) -> &T

Get the value of the descendant.

§Examples
use std::path::PathBuf;
use std::path::Path;
use dir_structure::dir_descendants::DirDescendant;

let descendant = DirDescendant::<_, Path>::new(
    "child",
    "root/a/b/child",
    "a/b/child",
    String::from("child_value"),
);
assert_eq!(descendant.value(), &String::from("child_value"));
Source

pub fn into_value(self) -> T

Turns the descendant into its value.

§Examples
use std::path::Path;
use dir_structure::dir_descendants::DirDescendant;

let descendant = DirDescendant::<_, Path>::new(
    "child",
    "root/a/b/child",
    "a/b/child",
    String::from("child_value"),
);
assert_eq!(descendant.into_value(), String::from("child_value"));
Source

pub fn into_name(self) -> P::PathSegmentOwned

Turns the descendant into its name.

§Examples
use std::ffi::OsString;
use std::path::Path;
use dir_structure::dir_descendants::DirDescendant;

let descendant = DirDescendant::<_, Path>::new(
    "child",
    "root/a/b/child",
    "a/b/child",
    String::from("child_value"),
);
assert_eq!(descendant.into_name(), OsString::from("child"));
Source

pub fn into_path(self) -> P::OwnedPath

Turns the descendant into its path.

§Examples
use std::path::PathBuf;
use std::path::Path;
use dir_structure::dir_descendants::DirDescendant;

let descendant = DirDescendant::<_, Path>::new(
    "child",
    "root/a/b/child",
    "a/b/child",
    String::from("child_value"),
);
assert_eq!(descendant.into_path(), PathBuf::from("root/a/b/child"));
Source

pub fn name_mut(&mut self) -> &mut P::PathSegmentOwned

Get a mutable reference to the name of the directory descendant. This is a mutable version of DirDescendant::name.

§Examples
use std::ffi::OsString;
use std::path::Path;
use dir_structure::dir_descendants::DirDescendant;

let mut descendant = DirDescendant::<_, Path>::new(
    "child",
    "root/a/b/child",
    "a/b/child",
    String::from("child_value"),
);
*descendant.name_mut() = OsString::from("new_child");
assert_eq!(descendant.name(), &OsString::from("new_child"));
Source

pub fn value_mut(&mut self) -> &mut T

Get a mutable reference to the value of the directory descendant. This is a mutable version of DirDescendant::value.

§Examples
use std::path::Path;
use dir_structure::dir_descendants::DirDescendant;

let mut descendant = DirDescendant::<_, Path>::new(
    "child",
    "root/a/b/child",
    "a/b/child",
    String::from("child_value"),
);
*descendant.value_mut() = String::from("new_child_value");
assert_eq!(descendant.value(), &String::from("new_child_value"));
Source

pub fn as_ref(&self) -> DirDescendant<&T, P>

Clones the directory name and paths, but makes the value a reference to the original value.

§Examples
use std::path::Path;
use dir_structure::dir_descendants::DirDescendant;

let descendant = DirDescendant::<_, Path>::new(
    "child",
    "root/a/b/child",
    "a/b/child",
    String::from("child_value"),
);

let ref_descendant = descendant.as_ref();
assert_eq!(ref_descendant.name(), descendant.name());
assert_eq!(ref_descendant.path(), descendant.path());
assert_eq!(ref_descendant.path_relative_to_ascendant(), descendant.path_relative_to_ascendant());
assert_eq!(ref_descendant.value(), &descendant.value());
Source

pub fn as_mut(&mut self) -> DirDescendant<&mut T, P>

Clones the directory name and paths, but makes the value a mutable reference to the original value.

§Examples
use std::path::Path;
use dir_structure::dir_descendants::DirDescendant;

let mut descendant = DirDescendant::<_, Path>::new(
    "child",
    "root/a/b/child",
    "a/b/child",
    String::from("child_value"),
);

let mut mut_ref_descendant = descendant.as_mut();
mut_ref_descendant.value_mut().push_str("_new");
assert_eq!(descendant.value(), &String::from("child_value_new"));
Source

pub fn map<F, U>(self, f: F) -> DirDescendant<U, P>
where F: FnOnce(T) -> U,

Maps the value of the directory descendant.

§Examples
use std::path::Path;
use dir_structure::dir_descendants::DirDescendant;

let descendant = DirDescendant::<_, Path>::new(
    "child",
    "root/a/b/child",
    "a/b/child",
    String::from("child_value"),
);
let mapped = descendant.map(|v| v.len());
assert_eq!(mapped.value(), &11);

Trait Implementations§

Source§

impl<T, P: PathType + ?Sized> AssertEq for DirDescendant<T, P>
where for<'__trivial> P::PathSegmentOwned: AssertEq<P::PathSegmentOwned> + Debug, for<'__trivial, '__trivial> P::OwnedPath: AssertEq<P::OwnedPath> + Debug, for<'__trivial> T: AssertEq<T> + Debug,

Source§

fn assert_eq( &self, other: &Self, path: &mut AssertPath, init_left: &impl Display, init_right: &impl Display, )

Asserts that self is equal to other, panicking if they are not equal. Read more
Source§

impl<T: Clone, P: PathType + ?Sized> Clone for DirDescendant<T, P>

Source§

fn clone(&self) -> Self

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<T: Debug, P: PathType + ?Sized> Debug for DirDescendant<T, P>

Source§

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

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

impl<T> Deref for DirDescendant<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T> DerefMut for DirDescendant<T>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<T, F: FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P>, P: PathType + ?Sized> Extend<DirDescendant<T, P>> for DirDescendants<T, F, P>

Source§

fn extend<I: IntoIterator<Item = DirDescendant<T, P>>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<T, F: FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P>, P: PathType + ?Sized> FromIterator<DirDescendant<T, P>> for DirDescendants<T, F, P>

Source§

fn from_iter<I: IntoIterator<Item = DirDescendant<T, P>>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<T: Hash, P: Hash + PathType + ?Sized> Hash for DirDescendant<T, P>

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<T: Ord, P: Ord + PathType + ?Sized> Ord for DirDescendant<T, P>

Source§

fn cmp(&self, other: &DirDescendant<T, P>) -> 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<T: PartialEq, P: PartialEq + PathType + ?Sized> PartialEq for DirDescendant<T, P>

Source§

fn eq(&self, other: &DirDescendant<T, P>) -> 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<T: PartialOrd, P: PartialOrd + PathType + ?Sized> PartialOrd for DirDescendant<T, P>

Source§

fn partial_cmp(&self, other: &DirDescendant<T, P>) -> 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<T: Eq, P: Eq + PathType + ?Sized> Eq for DirDescendant<T, P>

Source§

impl<T, P: PathType + ?Sized> StructuralPartialEq for DirDescendant<T, P>

Auto Trait Implementations§

§

impl<T, P> Freeze for DirDescendant<T, P>

§

impl<T, P> RefUnwindSafe for DirDescendant<T, P>

§

impl<T, P> Send for DirDescendant<T, P>
where T: Send, P: ?Sized,

§

impl<T, P> Sync for DirDescendant<T, P>
where T: Sync, P: ?Sized,

§

impl<T, P> Unpin for DirDescendant<T, P>
where <P as PathType>::PathSegmentOwned: Unpin, <P as PathType>::OwnedPath: Unpin, T: Unpin, P: ?Sized,

§

impl<T, P> UnwindSafe for DirDescendant<T, P>

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<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<T> DirStructureItem for T

Source§

fn read(path: impl AsRef<<FsVfs as VfsCore>::Path>) -> VfsResult<Self, FsVfs>
where Self: ReadFrom<'static, FsVfs> + Sized,

Uses the ReadFrom implementation to read the structure from disk, from the specified path.
Source§

fn write<'a, 'vfs: 'a>( &'a self, path: impl AsRef<<FsVfs as VfsCore>::Path>, ) -> VfsResult<(), FsVfs>
where Self: WriteTo<'vfs, FsVfs>,

Uses the WriteTo implementation to write the structure to disk at the specified path.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.
Source§

impl<T> ErasedDestructor for T
where T: 'static,