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>
impl<T, P: PathType + ?Sized> DirDescendant<T, P>
Sourcepub fn new(
name: impl Into<P::PathSegmentOwned>,
path: impl Into<P::OwnedPath>,
path_relative_to_ascendant: impl Into<P::OwnedPath>,
value: T,
) -> Self
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"));Sourcepub fn name(&self) -> &P::PathSegmentOwned
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"));Sourcepub fn path(&self) -> &P
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"));Sourcepub fn path_relative_to_ascendant(&self) -> &P
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"));Sourcepub fn value(&self) -> &T
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"));Sourcepub fn into_value(self) -> T
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"));Sourcepub fn into_name(self) -> P::PathSegmentOwned
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"));Sourcepub fn into_path(self) -> P::OwnedPath
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"));Sourcepub fn name_mut(&mut self) -> &mut P::PathSegmentOwned
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"));Sourcepub fn value_mut(&mut self) -> &mut T
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"));Sourcepub fn as_ref(&self) -> DirDescendant<&T, P>
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());Sourcepub fn as_mut(&mut self) -> DirDescendant<&mut T, P>
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"));Sourcepub fn map<F, U>(self, f: F) -> DirDescendant<U, P>where
F: FnOnce(T) -> U,
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,
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§impl<T> Deref for DirDescendant<T>
impl<T> Deref for DirDescendant<T>
Source§impl<T> DerefMut for DirDescendant<T>
impl<T> DerefMut for DirDescendant<T>
Source§impl<T, F: FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P>, P: PathType + ?Sized> Extend<DirDescendant<T, P>> for DirDescendants<T, F, P>
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)
fn extend<I: IntoIterator<Item = DirDescendant<T, P>>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<T, F: FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P>, P: PathType + ?Sized> FromIterator<DirDescendant<T, P>> for DirDescendants<T, F, P>
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
fn from_iter<I: IntoIterator<Item = DirDescendant<T, P>>>(iter: I) -> Self
Source§impl<T: Ord, P: Ord + PathType + ?Sized> Ord for DirDescendant<T, P>
impl<T: Ord, P: Ord + PathType + ?Sized> Ord for DirDescendant<T, P>
Source§fn cmp(&self, other: &DirDescendant<T, P>) -> Ordering
fn cmp(&self, other: &DirDescendant<T, P>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T: PartialOrd, P: PartialOrd + PathType + ?Sized> PartialOrd for DirDescendant<T, P>
impl<T: PartialOrd, P: PartialOrd + PathType + ?Sized> PartialOrd for DirDescendant<T, P>
impl<T: Eq, P: Eq + PathType + ?Sized> Eq for DirDescendant<T, P>
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>where
<P as PathType>::PathSegmentOwned: RefUnwindSafe,
<P as PathType>::OwnedPath: RefUnwindSafe,
T: RefUnwindSafe,
P: ?Sized,
impl<T, P> Send for DirDescendant<T, P>
impl<T, P> Sync for DirDescendant<T, P>
impl<T, P> Unpin for DirDescendant<T, P>
impl<T, P> UnwindSafe for DirDescendant<T, P>where
<P as PathType>::PathSegmentOwned: UnwindSafe,
<P as PathType>::OwnedPath: UnwindSafe,
T: UnwindSafe,
P: ?Sized,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<T> DirStructureItem for T
impl<T> DirStructureItem for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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