pub struct DirChildSingle<T, F: Filter<P>, P: PathType + ?Sized = Path> { /* private fields */ }Expand description
A structure that represents a directory where only one of the children pass the filter F.
This is useful if you want to select one specific file, by the file prefix / stem, but you don’t care about the extension.
Implementations§
Source§impl<T, F: Filter<P>, P: PathType + ?Sized> DirChildSingle<T, F, P>
impl<T, F: Filter<P>, P: PathType + ?Sized> DirChildSingle<T, F, 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 DirChildSingle with the specified file name and value.
§Examples
use std::ffi::OsString;
use dir_structure::NoFilter;
use dir_structure::dir_children::DirChildSingle;
let d = DirChildSingle::<_, NoFilter>::new("file.txt", "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 dir_structure::NoFilter;
use dir_structure::dir_children::DirChildSingle;
let d = DirChildSingle::<_, NoFilter>::new("file.txt", "file".to_owned());
assert_eq!(d.file_name(), &OsString::from("file.txt"));
assert_eq!(d.value(), &"file".to_owned());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 version of file_name.
§Examples
use std::ffi::OsString;
use dir_structure::NoFilter;
use dir_structure::dir_children::DirChildSingle;
let mut d = DirChildSingle::<_, NoFilter>::new("file.txt", "file".to_owned());
assert_eq!(d.file_name_mut(), &mut OsString::from("file.txt"));
assert_eq!(d.value_mut(), &mut "file".to_owned());Sourcepub fn value(&self) -> &T
pub fn value(&self) -> &T
Gets the value of the child.
§Examples
use std::ffi::OsString;
use dir_structure::NoFilter;
use dir_structure::dir_children::DirChildSingle;
let d = DirChildSingle::<_, NoFilter>::new("file.txt", "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. Mutable reference version of Self::value.
§Examples
use std::ffi::OsString;
use dir_structure::NoFilter;
use dir_structure::dir_children::DirChildSingle;
let mut d = DirChildSingle::<_, NoFilter>::new("file.txt", "file".to_owned());
assert_eq!(d.value_mut(), &mut "file".to_owned());Sourcepub fn as_ref(&self) -> DirChildSingle<&T, F, P>
pub fn as_ref(&self) -> DirChildSingle<&T, F, P>
Converts &DirChildSingle<T, F> to DirChildSingle<&T, F>.
§Examples
use std::ffi::OsString;
use dir_structure::NoFilter;
use dir_structure::dir_children::DirChildSingle;
let d = DirChildSingle::<_, NoFilter>::new("file.txt", "file".to_owned());
let d_ref: DirChildSingle<&String, NoFilter> = d.as_ref();
assert_eq!(d_ref.file_name(), &OsString::from("file.txt"));
assert_eq!(d_ref.value(), &&"file".to_owned());Sourcepub fn as_mut(&mut self) -> DirChildSingle<&mut T, F, P>
pub fn as_mut(&mut self) -> DirChildSingle<&mut T, F, P>
Converts &mut DirChildSingle<T, F> to DirChildSingle<&mut T, F>.
This clones the OsString and PathBuf used for the name and path.
§Examples
use std::ffi::OsString;
use dir_structure::NoFilter;
use dir_structure::dir_children::DirChildSingle;
let mut d = DirChildSingle::<_, NoFilter>::new("file.txt", "file".to_owned());
let mut d_mut: DirChildSingle<&mut String, NoFilter> = d.as_mut();
d_mut.value_mut().push_str("_modified");
assert_eq!(d.value(), &"file_modified".to_owned());Sourcepub fn map<T2, F2>(self, f: F2) -> DirChildSingle<T2, F, P>where
F2: FnOnce(T) -> T2,
pub fn map<T2, F2>(self, f: F2) -> DirChildSingle<T2, F, P>where
F2: FnOnce(T) -> T2,
Maps the value of the child to a new value.
§Examples
use std::ffi::OsString;
use dir_structure::NoFilter;
use dir_structure::dir_children::DirChildSingle;
let d = DirChildSingle::<_, NoFilter>::new("file.txt", "file".to_owned());
let d2 = d.map(|s| s.to_uppercase());
assert_eq!(d2.value(), &"FILE".to_owned());Sourcepub fn map_filter<F2>(self) -> DirChildSingle<T, F2, P>where
F2: Filter<P>,
pub fn map_filter<F2>(self) -> DirChildSingle<T, F2, P>where
F2: Filter<P>,
Map the filter to another Filter type.
§Examples
use std::ffi::OsString;
use dir_structure::NoFilter;
use dir_structure::dir_children::DirChildSingle;
use dir_structure::traits::vfs::PathType;
struct Filt;
impl<P: PathType + ?Sized> dir_structure::dir_children::Filter<P> for Filt {
fn allows(_path: &P) -> bool {
true
}
}
let d = DirChildSingle::<_, NoFilter>::new("file.txt", "file".to_owned());
let d2: DirChildSingle<_, Filt> = d.map_filter::<Filt>();
assert_eq!(d2.file_name(), &OsString::from("file.txt"));
assert_eq!(d2.value(), &"file".to_owned());Trait Implementations§
Source§impl<T, F: Filter<P>, P: PathType + ?Sized> AssertEq for DirChildSingle<T, F, P>where
for<'__trivial> P::PathSegmentOwned: AssertEq<P::PathSegmentOwned> + Debug,
for<'__trivial> T: AssertEq<T> + Debug,
impl<T, F: Filter<P>, P: PathType + ?Sized> AssertEq for DirChildSingle<T, F, P>where
for<'__trivial> P::PathSegmentOwned: AssertEq<P::PathSegmentOwned> + Debug,
for<'__trivial> T: AssertEq<T> + Debug,
Source§impl<T: Clone, F: Clone + Filter<P>, P: Clone + PathType + ?Sized> Clone for DirChildSingle<T, F, P>where
P::PathSegmentOwned: Clone,
impl<T: Clone, F: Clone + Filter<P>, P: Clone + PathType + ?Sized> Clone for DirChildSingle<T, F, P>where
P::PathSegmentOwned: Clone,
Source§fn clone(&self) -> DirChildSingle<T, F, P>
fn clone(&self) -> DirChildSingle<T, F, P>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: Hash, F: Hash + Filter<P>, P: Hash + PathType + ?Sized> Hash for DirChildSingle<T, F, P>where
P::PathSegmentOwned: Hash,
impl<T: Hash, F: Hash + Filter<P>, P: Hash + PathType + ?Sized> Hash for DirChildSingle<T, F, P>where
P::PathSegmentOwned: Hash,
Source§impl<T: Ord, F: Ord + Filter<P>, P: Ord + PathType + ?Sized> Ord for DirChildSingle<T, F, P>where
P::PathSegmentOwned: Ord,
impl<T: Ord, F: Ord + Filter<P>, P: Ord + PathType + ?Sized> Ord for DirChildSingle<T, F, P>where
P::PathSegmentOwned: Ord,
Source§fn cmp(&self, other: &DirChildSingle<T, F, P>) -> Ordering
fn cmp(&self, other: &DirChildSingle<T, F, 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: PartialEq, F: PartialEq + Filter<P>, P: PartialEq + PathType + ?Sized> PartialEq for DirChildSingle<T, F, P>where
P::PathSegmentOwned: PartialEq,
impl<T: PartialEq, F: PartialEq + Filter<P>, P: PartialEq + PathType + ?Sized> PartialEq for DirChildSingle<T, F, P>where
P::PathSegmentOwned: PartialEq,
Source§impl<T: PartialOrd, F: PartialOrd + Filter<P>, P: PartialOrd + PathType + ?Sized> PartialOrd for DirChildSingle<T, F, P>where
P::PathSegmentOwned: PartialOrd,
impl<T: PartialOrd, F: PartialOrd + Filter<P>, P: PartialOrd + PathType + ?Sized> PartialOrd for DirChildSingle<T, F, P>where
P::PathSegmentOwned: PartialOrd,
Source§impl<'a, T, F: Filter<Vfs::Path>, Vfs: WriteSupportingVfs<'a>> WriteTo<'a, Vfs> for DirChildSingle<T, F, Vfs::Path>where
T: WriteTo<'a, Vfs>,
impl<'a, T, F: Filter<Vfs::Path>, Vfs: WriteSupportingVfs<'a>> WriteTo<'a, Vfs> for DirChildSingle<T, F, Vfs::Path>where
T: WriteTo<'a, Vfs>,
impl<T: Eq, F: Eq + Filter<P>, P: Eq + PathType + ?Sized> Eq for DirChildSingle<T, F, P>where
P::PathSegmentOwned: Eq,
impl<T, F: Filter<P>, P: PathType + ?Sized> StructuralPartialEq for DirChildSingle<T, F, P>
Auto Trait Implementations§
impl<T, F, P> Freeze for DirChildSingle<T, F, P>
impl<T, F, P> RefUnwindSafe for DirChildSingle<T, F, P>where
<P as PathType>::PathSegmentOwned: RefUnwindSafe,
T: RefUnwindSafe,
F: RefUnwindSafe,
P: RefUnwindSafe + ?Sized,
impl<T, F, P> Send for DirChildSingle<T, F, P>
impl<T, F, P> Sync for DirChildSingle<T, F, P>
impl<T, F, P> Unpin for DirChildSingle<T, F, P>
impl<T, F, P> UnwindSafe for DirChildSingle<T, F, P>where
<P as PathType>::PathSegmentOwned: UnwindSafe,
T: UnwindSafe,
F: UnwindSafe,
P: UnwindSafe + ?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