pub struct DirChild<T, P: PathType + ?Sized = Path> { /* private fields */ }Expand description
A single child of a DirChildren structure.
Implementations§
Source§impl<T, P: PathType + ?Sized> DirChild<T, P>
impl<T, P: PathType + ?Sized> DirChild<T, P>
Sourcepub fn new(file_name: impl Into<P::PathSegmentOwned>, value: T) -> Self
pub fn new(file_name: impl Into<P::PathSegmentOwned>, value: T) -> Self
Creates a new DirChild with the specified file name and value.
§Examples
use std::ffi::OsString;
use std::path::Path;
use dir_structure::dir_children::DirChild;
let d = DirChild::<_, Path>::new("file.txt".to_owned(), "file".to_owned());
assert_eq!(d.file_name(), &OsString::from("file.txt"));
assert_eq!(d.value(), &"file".to_owned());Sourcepub fn file_name(&self) -> &P::PathSegmentOwned
pub fn file_name(&self) -> &P::PathSegmentOwned
Gets the file name of the child (or the name of the directory; the last segment in the path).
§Examples
use std::ffi::OsString;
use std::path::Path;
use dir_structure::dir_children::DirChild;
let d = DirChild::<_, Path>::new("file.txt".to_owned(), "file".to_owned());
assert_eq!(d.file_name(), &OsString::from("file.txt"));Sourcepub fn file_name_mut(&mut self) -> &mut P::PathSegmentOwned
pub fn file_name_mut(&mut self) -> &mut P::PathSegmentOwned
Gets the file name of the child (or the name of the directory; the last segment in the path).
Mutable reference version of Self::file_name.
§Examples
use std::ffi::OsString;
use std::path::Path;
use dir_structure::dir_children::DirChild;
let mut d = DirChild::<_, Path>::new("file.txt".to_owned(), "file".to_owned());
assert_eq!(d.file_name(), &OsString::from("file.txt"));
*d.file_name_mut() = OsString::from("new_file.txt");
assert_eq!(d.file_name(), &OsString::from("new_file.txt"));Sourcepub fn value(&self) -> &T
pub fn value(&self) -> &T
Gets the value of the child.
This is the parsed value of the file / directory.
§Examples
use std::ffi::OsString;
use std::path::Path;
use dir_structure::dir_children::DirChild;
let d = DirChild::<_, Path>::new("file.txt".to_owned(), "file".to_owned());
assert_eq!(d.value(), &"file".to_owned());Sourcepub fn value_mut(&mut self) -> &mut T
pub fn value_mut(&mut self) -> &mut T
Gets the value of the child.
This is the parsed value of the file / directory.
Mutable reference version of Self::value.
§Examples
use std::ffi::OsString;
use std::path::Path;
use dir_structure::dir_children::DirChild;
let mut d = DirChild::<_, Path>::new("file.txt".to_owned(), "file".to_owned());
assert_eq!(d.value(), &"file".to_owned());
*d.value_mut() = "new_file".to_owned();
assert_eq!(d.value(), &"new_file".to_owned());Sourcepub fn map_file_name<F, O>(self, f: F) -> Self
pub fn map_file_name<F, O>(self, f: F) -> Self
Maps the file name of this DirChild to a new value.
§Examples
use std::ffi::OsString;
use std::path::Path;
use dir_structure::dir_children::DirChild;
let d = DirChild::<_, Path>::new("file.txt".to_owned(), "file".to_owned());
assert_eq!(d.map_file_name(|s| s.to_str().unwrap().to_uppercase()), DirChild::new("FILE.TXT", "file".to_owned()));Sourcepub fn map_value<U, F>(self, f: F) -> DirChild<U, P>where
F: FnOnce(T) -> U,
pub fn map_value<U, F>(self, f: F) -> DirChild<U, P>where
F: FnOnce(T) -> U,
Maps the value of this DirChild to a new type.
This is useful for converting the value to a different type,
for example, if you want to convert the value to a different
type of DirStructureItem.
§Examples
use std::ffi::OsString;
use std::path::Path;
use dir_structure::dir_children::DirChild;
use dir_structure::std_types::FileString;
let d = DirChild::<_, Path>::new("file.txt".to_owned(), "file".to_owned());
assert_eq!(d.map_value(|v| FileString(v)), DirChild::new("file.txt".to_owned(), FileString("file".to_owned())));Trait Implementations§
Source§impl<T, P: PathType + ?Sized> AssertEq for DirChild<T, P>where
for<'__trivial> P::PathSegmentOwned: AssertEq<P::PathSegmentOwned> + Debug,
for<'__trivial> T: AssertEq<T> + Debug,
impl<T, P: PathType + ?Sized> AssertEq for DirChild<T, P>where
for<'__trivial> P::PathSegmentOwned: AssertEq<P::PathSegmentOwned> + Debug,
for<'__trivial> T: AssertEq<T> + Debug,
Source§impl<T, P: PathType + ?Sized, F> Extend<DirChild<T, P>> for DirChildren<T, F, P>where
F: Filter<P>,
impl<T, P: PathType + ?Sized, F> Extend<DirChild<T, P>> for DirChildren<T, F, P>where
F: Filter<P>,
Source§fn extend<I: IntoIterator<Item = DirChild<T, P>>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = DirChild<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, P: PathType + ?Sized, F> FromIterator<DirChild<T, P>> for DirChildren<T, F, P>where
F: Filter<P>,
impl<T, P: PathType + ?Sized, F> FromIterator<DirChild<T, P>> for DirChildren<T, F, P>where
F: Filter<P>,
Source§impl<T, F, P: PathType + ?Sized> FromIterator<DirChild<T, P>> for ForceCreateDirChildren<T, F, P>where
F: Filter<P>,
impl<T, F, P: PathType + ?Sized> FromIterator<DirChild<T, P>> for ForceCreateDirChildren<T, F, P>where
F: Filter<P>,
Source§impl<T: PartialEq, P: PartialEq + PathType + ?Sized> PartialEq for DirChild<T, P>where
P::PathSegmentOwned: PartialEq,
impl<T: PartialEq, P: PartialEq + PathType + ?Sized> PartialEq for DirChild<T, P>where
P::PathSegmentOwned: PartialEq,
impl<T: Eq, P: Eq + PathType + ?Sized> Eq for DirChild<T, P>where
P::PathSegmentOwned: Eq,
impl<T, P: PathType + ?Sized> StructuralPartialEq for DirChild<T, P>
Auto Trait Implementations§
impl<T, P> Freeze for DirChild<T, P>
impl<T, P> RefUnwindSafe for DirChild<T, P>
impl<T, P> Send for DirChild<T, P>
impl<T, P> Sync for DirChild<T, P>
impl<T, P> Unpin for DirChild<T, P>
impl<T, P> UnwindSafe for DirChild<T, P>
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<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