pub struct DirDescendants<T, F: FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P> = NoFilter, P: PathType + ?Sized = Path> { /* private fields */ }Expand description
A structure representing the descendants of a directory.
This is different from DirChildren, as the descendants include all
files and folders within the directory, not just the immediate children, as is the case with
DirChildren.
The F type parameter allows for custom filtering of the descendants, as follows:
- its
FolderFilterimplementation tells us whether to attempt to parse a specific folder asT, storing it into the result set. - its
FolderRecurseFiltertells us whether to recurse into a specific folder, but not necessarily parse it asT. - its
FileFilterimplementation tells us whether to attempt to parse a specific file asT, storing it into the result set.
* note that FolderFilter and FolderRecurseFilter may both allow the same path, in which case we will both recurse
into the folder, and attempt to parse it as a T.
Implementations§
Source§impl<T, F: FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P>, P: PathType + ?Sized> DirDescendants<T, F, P>
impl<T, F: FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P>, P: PathType + ?Sized> DirDescendants<T, F, P>
Sourcepub fn new(descendants: Vec<DirDescendant<T, P>>) -> Self
pub fn new(descendants: Vec<DirDescendant<T, P>>) -> Self
Create a new DirDescendants instance from a list of DirDescendants.
§Examples
use dir_structure::{dir_descendants::{DirDescendants, DirDescendant}, NoFilter};
let descendants = DirDescendants::<(), NoFilter>::new(vec![]);
assert!(descendants.is_empty());
let descendants = DirDescendants::<(), NoFilter>::new(vec![
DirDescendant::new("child1", "child1", "child1", ()),
DirDescendant::new("child2", "child2", "child2", ()),
]);
assert_eq!(descendants.len(), 2);Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of descendants.
§Examples
use dir_structure::{dir_descendants::{DirDescendants, DirDescendant}, NoFilter};
let descendants = DirDescendants::<(), NoFilter>::new(vec![]);
assert_eq!(descendants.len(), 0);
let descendants = DirDescendants::<(), NoFilter>::new(vec![
DirDescendant::new("child1", "child1", "child1", ()),
DirDescendant::new("child2", "child2", "child2", ()),
]);
assert_eq!(descendants.len(), 2);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns whether there are no descendants.
§Examples
use dir_structure::{dir_descendants::{DirDescendants, DirDescendant}, NoFilter};
let descendants = DirDescendants::<(), NoFilter>::new(vec![]);
assert_eq!(descendants.is_empty(), true);
let descendants = DirDescendants::<(), NoFilter>::new(vec![
DirDescendant::new("child1", "child1", "child1", ()),
DirDescendant::new("child2", "child2", "child2", ()),
]);
assert_eq!(descendants.is_empty(), false);Sourcepub fn iter(&self) -> DirDescendantsIter<'_, T, P> ⓘ
pub fn iter(&self) -> DirDescendantsIter<'_, T, P> ⓘ
Returns an iterator over the descendants.
§Examples
use dir_structure::{dir_descendants::{DirDescendants, DirDescendant}, NoFilter};
let descendants = DirDescendants::<(), NoFilter>::new(vec![]);
let mut i = descendants.iter();
assert_eq!(i.next(), None);
let descendants = DirDescendants::<(), NoFilter>::new(vec![
DirDescendant::new("child1", "child1", "child1", ()),
DirDescendant::new("child2", "child2", "child2", ()),
]);
let mut i = descendants.iter();
assert_eq!(i.next(), Some(&DirDescendant::new("child1", "child1", "child1", ())));
assert_eq!(i.next(), Some(&DirDescendant::new("child2", "child2", "child2", ())));
assert_eq!(i.next(), None);Sourcepub fn iter_mut(&mut self) -> DirDescendantsIterMut<'_, T, P> ⓘ
pub fn iter_mut(&mut self) -> DirDescendantsIterMut<'_, T, P> ⓘ
Returns an iterator over the mutable descendants.
§Examples
use dir_structure::{dir_descendants::{DirDescendants, DirDescendant}, NoFilter};
let mut descendants = DirDescendants::<(), NoFilter>::new(vec![]);
let mut i = descendants.iter_mut();
assert_eq!(i.next(), None);
let mut descendants = DirDescendants::<(), NoFilter>::new(vec![
DirDescendant::new("child1", "child1", "child1", ()),
DirDescendant::new("child2", "child2", "child2", ()),
]);
let mut i = descendants.iter_mut();
assert_eq!(i.next(), Some(&mut DirDescendant::new("child1", "child1", "child1", ())));
assert_eq!(i.next(), Some(&mut DirDescendant::new("child2", "child2", "child2", ())));
assert_eq!(i.next(), None);Sourcepub fn get(&self, index: usize) -> Option<&DirDescendant<T, P>>
pub fn get(&self, index: usize) -> Option<&DirDescendant<T, P>>
Returns the descendant at the given index, or None if out of bounds.
§Examples
use dir_structure::{dir_descendants::{DirDescendants, DirDescendant}, NoFilter};
let descendants = DirDescendants::<(), NoFilter>::new(vec![
DirDescendant::new("child1", "child1", "child1", ()),
DirDescendant::new("child2", "child2", "child2", ()),
]);
assert_eq!(descendants.len(), 2);
assert_eq!(descendants.get(0), Some(&DirDescendant::new("child1", "child1", "child1", ())));
assert_eq!(descendants.get(1), Some(&DirDescendant::new("child2", "child2", "child2", ())));
assert_eq!(descendants.get(2), None);
assert_eq!(descendants.get(100), None);Sourcepub fn get_mut(&mut self, index: usize) -> Option<&mut DirDescendant<T, P>>
pub fn get_mut(&mut self, index: usize) -> Option<&mut DirDescendant<T, P>>
Returns a mutable reference to the descendant at the given index, or None if out of bounds.
This is a mutable version of get.
§Examples
use dir_structure::{dir_descendants::{DirDescendants, DirDescendant}, NoFilter};
let mut descendants = DirDescendants::<(), NoFilter>::new(vec![
DirDescendant::new("child1", "child1", "child1", ()),
DirDescendant::new("child2", "child2", "child2", ()),
]);
assert_eq!(descendants.len(), 2);
assert_eq!(descendants.get_mut(0), Some(&mut DirDescendant::new("child1", "child1", "child1", ())));
assert_eq!(descendants.get_mut(1), Some(&mut DirDescendant::new("child2", "child2", "child2", ())));
assert_eq!(descendants.get_mut(2), None);
assert_eq!(descendants.get_mut(100), None);Sourcepub fn get_by_name(
&self,
name: impl AsRef<P::PathSegmentRef>,
) -> Option<&DirDescendant<T, P>>where
P::PathSegmentRef: PartialEq,
pub fn get_by_name(
&self,
name: impl AsRef<P::PathSegmentRef>,
) -> Option<&DirDescendant<T, P>>where
P::PathSegmentRef: PartialEq,
Returns the descendant with the given name, or None if not found.
§Examples
use dir_structure::{dir_descendants::{DirDescendants, DirDescendant}, NoFilter};
let descendants = DirDescendants::<String, NoFilter>::new(vec![
DirDescendant::new("child1", "root/a/b/child1", "a/b/child1", "value1".into()),
DirDescendant::new("child2", "root/a/b/child2", "a/b/child2", "value2".into()),
]);
assert_eq!(descendants.get_by_name("child1"), Some(&DirDescendant::new("child1", "root/a/b/child1", "a/b/child1", "value1".into())));
assert_eq!(descendants.get_by_name("child2"), Some(&DirDescendant::new("child2", "root/a/b/child2", "a/b/child2", "value2".into())));
assert_eq!(descendants.get_by_name("child3"), None);
assert_eq!(descendants.get_by_name("nonexistent"), None);Sourcepub fn get_by_name_mut(
&mut self,
name: impl AsRef<P::PathSegmentRef>,
) -> Option<&mut DirDescendant<T, P>>where
P::PathSegmentRef: PartialEq,
pub fn get_by_name_mut(
&mut self,
name: impl AsRef<P::PathSegmentRef>,
) -> Option<&mut DirDescendant<T, P>>where
P::PathSegmentRef: PartialEq,
Returns a mutable reference to the descendant with the given name, or None if not found.
This is a mutable version of get_by_name.
§Examples
use dir_structure::{dir_descendants::{DirDescendants, DirDescendant}, NoFilter};
let mut descendants = DirDescendants::<String, NoFilter>::new(vec![
DirDescendant::new("child1", "root/a/b/child1", "a/b/child1", "value1".into()),
DirDescendant::new("child2", "root/a/b/child2", "a/b/child2", "value2".into()),
]);
assert_eq!(descendants.get_by_name_mut("child1"), Some(&mut DirDescendant::new("child1", "root/a/b/child1", "a/b/child1", "value1".into())));
assert_eq!(descendants.get_by_name_mut("child2"), Some(&mut DirDescendant::new("child2", "root/a/b/child2", "a/b/child2", "value2".into())));
assert_eq!(descendants.get_by_name_mut("child3"), None);
assert_eq!(descendants.get_by_name_mut("nonexistent"), None);Sourcepub fn get_value_by_name(
&self,
name: impl AsRef<P::PathSegmentRef>,
) -> Option<&T>where
P::PathSegmentRef: PartialEq,
pub fn get_value_by_name(
&self,
name: impl AsRef<P::PathSegmentRef>,
) -> Option<&T>where
P::PathSegmentRef: PartialEq,
Returns the value of the descendant with the given name, or None if not found.
§Examples
use dir_structure::{dir_descendants::{DirDescendants, DirDescendant}, NoFilter};
let descendants = DirDescendants::<String, NoFilter>::new(vec![
DirDescendant::new("child1", "root/a/b/child1", "a/b/child1", "value1".into()),
DirDescendant::new("child2", "root/a/b/child2", "a/b/child2", "value2".into()),
]);
assert_eq!(descendants.get_value_by_name("child1"), Some(&"value1".into()));
assert_eq!(descendants.get_value_by_name("child2"), Some(&"value2".into()));
assert_eq!(descendants.get_value_by_name("child3"), None);
assert_eq!(descendants.get_value_by_name("nonexistent"), None);Sourcepub fn get_value_by_name_mut(
&mut self,
name: impl AsRef<P::PathSegmentRef>,
) -> Option<&mut T>where
P::PathSegmentRef: PartialEq,
pub fn get_value_by_name_mut(
&mut self,
name: impl AsRef<P::PathSegmentRef>,
) -> Option<&mut T>where
P::PathSegmentRef: PartialEq,
Returns a mutable reference to the value of the descendant with the given name, or None if not found.
This is a mutable version of get_value_by_name.
§Examples
use dir_structure::{dir_descendants::{DirDescendants, DirDescendant}, NoFilter};
let mut descendants = DirDescendants::<String, NoFilter>::new(vec![
DirDescendant::new("child1", "root/a/b/child1", "a/b/child1", "value1".into()),
DirDescendant::new("child2", "root/a/b/child2", "a/b/child2", "value2".into()),
]);
assert_eq!(descendants.get_value_by_name_mut("child1"), Some(&mut "value1".into()));
assert_eq!(descendants.get_value_by_name_mut("child2"), Some(&mut "value2".into()));
assert_eq!(descendants.get_value_by_name_mut("child3"), None);
assert_eq!(descendants.get_value_by_name_mut("nonexistent"), None);Sourcepub fn get_by_path(&self, path: impl AsRef<P>) -> Option<&DirDescendant<T, P>>where
P: PartialEq,
pub fn get_by_path(&self, path: impl AsRef<P>) -> Option<&DirDescendant<T, P>>where
P: PartialEq,
Returns the descendant with the given path, or None if not found.
§Examples
use dir_structure::{dir_descendants::{DirDescendants, DirDescendant}, NoFilter};
let descendants = DirDescendants::<String, NoFilter>::new(vec![
DirDescendant::new("child1", "root/a/b/child1", "a/b/child1", "value1".into()),
DirDescendant::new("child2", "root/a/b/child2", "a/b/child2", "value2".into()),
]);
assert_eq!(descendants.get_by_path("root/a/b/child1"), Some(&DirDescendant::new("child1", "root/a/b/child1", "a/b/child1", "value1".into())));
assert_eq!(descendants.get_by_path("root/a/b/child2"), Some(&DirDescendant::new("child2", "root/a/b/child2", "a/b/child2", "value2".into())));
assert_eq!(descendants.get_by_path("root/a/b/child3"), None);
assert_eq!(descendants.get_by_path("nonexistent"), None);Sourcepub fn get_by_path_mut(
&mut self,
path: impl AsRef<P>,
) -> Option<&mut DirDescendant<T, P>>where
P: PartialEq,
pub fn get_by_path_mut(
&mut self,
path: impl AsRef<P>,
) -> Option<&mut DirDescendant<T, P>>where
P: PartialEq,
Returns a mutable reference to the descendant with the given path, or None if not found.
This is a mutable version of get_by_path.
§Examples
use dir_structure::{dir_descendants::{DirDescendants, DirDescendant}, NoFilter};
let mut descendants = DirDescendants::<String, NoFilter>::new(vec![
DirDescendant::new("child1", "root/a/b/child1", "a/b/child1", "value1".into()),
DirDescendant::new("child2", "root/a/b/child2", "a/b/child2", "value2".into()),
]);
assert_eq!(descendants.get_by_path_mut("root/a/b/child1"), Some(&mut DirDescendant::new("child1", "root/a/b/child1", "a/b/child1", "value1".into())));
assert_eq!(descendants.get_by_path_mut("root/a/b/child2"), Some(&mut DirDescendant::new("child2", "root/a/b/child2", "a/b/child2", "value2".into())));
assert_eq!(descendants.get_by_path_mut("root/a/b/child3"), None);
assert_eq!(descendants.get_by_path_mut("nonexistent"), None);Sourcepub fn get_value_by_path(&self, path: impl AsRef<P>) -> Option<&T>where
P: PartialEq,
pub fn get_value_by_path(&self, path: impl AsRef<P>) -> Option<&T>where
P: PartialEq,
Returns the value of the descendant with the given path, or None if not found.
§Examples
use dir_structure::{dir_descendants::{DirDescendants, DirDescendant}, NoFilter};
let descendants = DirDescendants::<String, NoFilter>::new(vec![
DirDescendant::new("child1", "root/a/b/child1", "a/b/child1", "value1".into()),
DirDescendant::new("child2", "root/a/b/child2", "a/b/child2", "value2".into()),
]);
assert_eq!(descendants.get_value_by_path("root/a/b/child1"), Some(&"value1".into()));
assert_eq!(descendants.get_value_by_path("root/a/b/child2"), Some(&"value2".into()));
assert_eq!(descendants.get_value_by_path("root/a/b/child3"), None);
assert_eq!(descendants.get_value_by_path("nonexistent"), None);Sourcepub fn get_value_by_path_mut(&mut self, path: impl AsRef<P>) -> Option<&mut T>where
P: PartialEq,
pub fn get_value_by_path_mut(&mut self, path: impl AsRef<P>) -> Option<&mut T>where
P: PartialEq,
Returns a mutable reference to the value of the descendant with the given path, or None if not found.
This is a mutable version of get_value_by_path.
§Examples
use dir_structure::{dir_descendants::{DirDescendants, DirDescendant}, NoFilter};
let mut descendants = DirDescendants::<String, NoFilter>::new(vec![
DirDescendant::new("child1", "root/a/b/child1", "a/b/child1", "value1".into()),
DirDescendant::new("child2", "root/a/b/child2", "a/b/child2", "value2".into()),
]);
assert_eq!(descendants.get_value_by_path_mut("root/a/b/child1"), Some(&mut "value1".into()));
assert_eq!(descendants.get_value_by_path_mut("root/a/b/child2"), Some(&mut "value2".into()));
assert_eq!(descendants.get_value_by_path_mut("root/a/b/child3"), None);
assert_eq!(descendants.get_value_by_path_mut("nonexistent"), None);Sourcepub fn get_by_relative_path(
&self,
path: impl AsRef<P>,
) -> Option<&DirDescendant<T, P>>where
P: PartialEq,
pub fn get_by_relative_path(
&self,
path: impl AsRef<P>,
) -> Option<&DirDescendant<T, P>>where
P: PartialEq,
Returns the descendant with the given path relative to the ascendant, or None if not found.
§Examples
use dir_structure::{dir_descendants::{DirDescendants, DirDescendant}, NoFilter};
let descendants = DirDescendants::<String, NoFilter>::new(vec![
DirDescendant::new("child1", "root/a/b/child1", "a/b/child1", "value1".into()),
DirDescendant::new("child2", "root/a/b/child2", "a/b/child2", "value2".into()),
]);
assert_eq!(descendants.get_by_relative_path("a/b/child1"), Some(&DirDescendant::new("child1", "root/a/b/child1", "a/b/child1", "value1".into())));
assert_eq!(descendants.get_by_relative_path("a/b/child2"), Some(&DirDescendant::new("child2", "root/a/b/child2", "a/b/child2", "value2".into())));
assert_eq!(descendants.get_by_relative_path("a/b/child3"), None);
assert_eq!(descendants.get_by_relative_path("nonexistent"), None);Sourcepub fn get_by_relative_path_mut(
&mut self,
path: impl AsRef<P>,
) -> Option<&mut DirDescendant<T, P>>where
P: PartialEq,
pub fn get_by_relative_path_mut(
&mut self,
path: impl AsRef<P>,
) -> Option<&mut DirDescendant<T, P>>where
P: PartialEq,
Returns a mutable reference to the descendant with the given path relative to the ascendant, or None if not found.
This is a mutable version of get_by_relative_path.
§Examples
use dir_structure::{dir_descendants::{DirDescendants, DirDescendant}, NoFilter};
let mut descendants = DirDescendants::<String, NoFilter>::new(vec![
DirDescendant::new("child1", "root/a/b/child1", "a/b/child1", "value1".into()),
DirDescendant::new("child2", "root/a/b/child2", "a/b/child2", "value2".into()),
]);
assert_eq!(descendants.get_by_relative_path_mut("a/b/child1"), Some(&mut DirDescendant::new("child1", "root/a/b/child1", "a/b/child1", "value1".into())));
assert_eq!(descendants.get_by_relative_path_mut("a/b/child2"), Some(&mut DirDescendant::new("child2", "root/a/b/child2", "a/b/child2", "value2".into())));
assert_eq!(descendants.get_by_relative_path_mut("a/b/child3"), None);
assert_eq!(descendants.get_by_relative_path_mut("nonexistent"), None);Sourcepub fn get_value_by_relative_path(&self, path: impl AsRef<P>) -> Option<&T>where
P: PartialEq,
pub fn get_value_by_relative_path(&self, path: impl AsRef<P>) -> Option<&T>where
P: PartialEq,
Returns the value of the descendant with the given path relative to the ascendant, or None if not found.
§Examples
use dir_structure::{dir_descendants::{DirDescendants, DirDescendant}, NoFilter};
let descendants = DirDescendants::<String, NoFilter>::new(vec![
DirDescendant::new("child1", "root/a/b/child1", "a/b/child1", "value1".into()),
DirDescendant::new("child2", "root/a/b/child2", "a/b/child2", "value2".into()),
]);
assert_eq!(descendants.get_value_by_relative_path("a/b/child1"), Some(&"value1".into()));
assert_eq!(descendants.get_value_by_relative_path("a/b/child2"), Some(&"value2".into()));
assert_eq!(descendants.get_value_by_relative_path("a/b/child3"), None);
assert_eq!(descendants.get_value_by_relative_path("nonexistent"), None);Sourcepub fn get_value_by_relative_path_mut(
&mut self,
path: impl AsRef<P>,
) -> Option<&mut T>where
P: PartialEq,
pub fn get_value_by_relative_path_mut(
&mut self,
path: impl AsRef<P>,
) -> Option<&mut T>where
P: PartialEq,
Returns a mutable reference to the value of the descendant with the given path relative to the ascendant, or None if not found.
This is a mutable version of get_value_by_relative_path.
§Examples
use dir_structure::{dir_descendants::{DirDescendants, DirDescendant}, NoFilter};
let mut descendants = DirDescendants::<String, NoFilter>::new(vec![
DirDescendant::new("child1", "root/a/b/child1", "a/b/child1", "value1".into()),
DirDescendant::new("child2", "root/a/b/child2", "a/b/child2", "value2".into()),
]);
assert_eq!(descendants.get_value_by_relative_path_mut("a/b/child1"), Some(&mut "value1".into()));
assert_eq!(descendants.get_value_by_relative_path_mut("a/b/child2"), Some(&mut "value2".into()));
assert_eq!(descendants.get_value_by_relative_path_mut("a/b/child3"), None);
assert_eq!(descendants.get_value_by_relative_path_mut("nonexistent"), None);Sourcepub fn map<U>(self, f: impl FnMut(T) -> U) -> DirDescendants<U, F, P>
pub fn map<U>(self, f: impl FnMut(T) -> U) -> DirDescendants<U, F, P>
Maps the descendants to another type.
§Examples
use dir_structure::{dir_descendants::{DirDescendants, DirDescendant}, NoFilter};
let descendants = DirDescendants::<String, NoFilter>::new(vec![
DirDescendant::new("child1", "root/a/b/child1", "a/b/child1", "value1".to_string()),
DirDescendant::new("child2", "root/a/b/child2", "a/b/child2", "value2abc1000".to_string()),
]);
let mapped = descendants.map(|s| s.len());
assert_eq!(mapped.len(), 2);
assert_eq!(mapped.get(0).unwrap().value(), &6); // "value1".len() == 6
assert_eq!(mapped.get(1).unwrap().value(), &13); // "value2abc1000".len() == 13
assert_eq!(mapped.get(2), None);
assert_eq!(mapped.get(100), None);Sourcepub fn map_filter<F2: FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P>>(
self,
) -> DirDescendants<T, F2, P>
pub fn map_filter<F2: FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P>>( self, ) -> DirDescendants<T, F2, P>
Maps the filter type to another type.
§Examples
use dir_structure::{dir_descendants::{DirDescendants, DirDescendant, FileFilter, FolderFilter, FolderRecurseFilter}, NoFilter};
struct MyFilter;
impl FileFilter for MyFilter {
fn allows(_file: &std::path::Path) -> bool { true }
}
impl FolderFilter for MyFilter {
fn allows(_folder: &std::path::Path) -> bool { true }
}
impl FolderRecurseFilter for MyFilter {
fn allows(_folder: &std::path::Path) -> bool { true }
}
let descendants = DirDescendants::<String, NoFilter>::new(vec![
DirDescendant::new("child1", "child1", "child1", "value1".to_string()),
DirDescendant::new("child2", "child2", "child2", "value2".to_string()),
]);
let descendants_with_my_filter: DirDescendants<String, MyFilter> = descendants.map_filter::<MyFilter>();Sourcepub fn push(&mut self, descendant: DirDescendant<T, P>)
pub fn push(&mut self, descendant: DirDescendant<T, P>)
Appends a descendant to the end of the list.
§Examples
use dir_structure::{dir_descendants::{DirDescendants, DirDescendant}, NoFilter};
let mut descendants = DirDescendants::<String, NoFilter>::new(vec![]);
assert!(descendants.is_empty());
descendants.push(DirDescendant::new("child1", "child1", "child1", "value1".to_string()));
assert_eq!(descendants.len(), 1);
let mut i = descendants.iter();
assert_eq!(i.next(), Some(&DirDescendant::new("child1", "child1", "child1", "value1".to_string())));
assert_eq!(i.next(), None);
descendants.push(DirDescendant::new("child2", "child2", "child2", "value2".to_string()));
assert_eq!(descendants.len(), 2);
let mut i = descendants.iter();
assert_eq!(i.next(), Some(&DirDescendant::new("child1", "child1", "child1", "value1".to_string())));
assert_eq!(i.next(), Some(&DirDescendant::new("child2", "child2", "child2", "value2".to_string())));
assert_eq!(i.next(), None);Sourcepub fn retain(&mut self, f: impl FnMut(&DirDescendant<T, P>) -> bool)
pub fn retain(&mut self, f: impl FnMut(&DirDescendant<T, P>) -> bool)
Retains only the descendants specified by the predicate.
§Examples
use dir_structure::{dir_descendants::{DirDescendants, DirDescendant}, NoFilter};
let mut descendants = DirDescendants::<String, NoFilter>::new(vec![
DirDescendant::new("child1", "child1", "child1", "value1".to_string()),
DirDescendant::new("child2", "child2", "child2", "value2".to_string()),
DirDescendant::new("child3", "child3", "child3", "value3".to_string()),
]);
descendants.retain(|d| d.name() == "child2");
assert_eq!(descendants.len(), 1);
assert_eq!(descendants.get(0).unwrap().name(), "child2");Sourcepub fn drain(
&mut self,
range: impl RangeBounds<usize>,
) -> DirDescendantsDrain<'_, T, P> ⓘ
pub fn drain( &mut self, range: impl RangeBounds<usize>, ) -> DirDescendantsDrain<'_, T, P> ⓘ
Drains the descendants in the specified range.
§Examples
use dir_structure::{dir_descendants::{DirDescendants, DirDescendant}, NoFilter};
let mut descendants = DirDescendants::<String, NoFilter>::new(vec![
DirDescendant::new("child1", "child1", "child1", "value1".to_string()),
DirDescendant::new("child2", "child2", "child2", "value2".to_string()),
DirDescendant::new("child3", "child3", "child3", "value3".to_string()),
]);
let drained: Vec<_> = descendants.drain(0..2).collect();
assert_eq!(drained, vec![
DirDescendant::new("child1", "child1", "child1", "value1".to_string()),
DirDescendant::new("child2", "child2", "child2", "value2".to_string()),
]);
assert_eq!(descendants.len(), 1);
assert_eq!(descendants.get(0).unwrap().name(), "child3");Sourcepub fn extract_if<'a, Fi>(
&'a mut self,
range: impl RangeBounds<usize>,
f: Fi,
) -> DirDescendantsExtractIf<'a, T, P, Fi> ⓘ
pub fn extract_if<'a, Fi>( &'a mut self, range: impl RangeBounds<usize>, f: Fi, ) -> DirDescendantsExtractIf<'a, T, P, Fi> ⓘ
Extracts the descendants in the specified range that satisfy the predicate.
§Examples
use dir_structure::{dir_descendants::{DirDescendants, DirDescendant}, NoFilter};
let mut descendants = DirDescendants::<String, NoFilter>::new(vec![
DirDescendant::new("child1", "child1", "child1", "value1".to_string()),
DirDescendant::new("child2", "child2", "child2", "value2".to_string()),
DirDescendant::new("child3", "child3", "child3", "value3".to_string()),
DirDescendant::new("child4", "child4", "child4", "value4".to_string()),
]);
let extracted: Vec<_> = descendants.extract_if(1..4, |d| d.name() == "child2" || d.name() == "child4").collect();
assert_eq!(extracted, vec![
DirDescendant::new("child2", "child2", "child2", "value2".to_string()),
DirDescendant::new("child4", "child4", "child4", "value4".to_string()),
]);
assert_eq!(descendants.len(), 2);
assert_eq!(descendants.get(0).unwrap().name(), "child1");
assert_eq!(descendants.get(1).unwrap().name(), "child3");Trait Implementations§
Source§impl<T, F: FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P>, P: PathType + ?Sized> AssertEq for DirDescendants<T, F, P>where
for<'__trivial> Vec<DirDescendant<T, P>>: AssertEq<Vec<DirDescendant<T, P>>> + Debug,
for<'__trivial> PhantomData<F>: AssertEq<PhantomData<F>> + Debug,
impl<T, F: FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P>, P: PathType + ?Sized> AssertEq for DirDescendants<T, F, P>where
for<'__trivial> Vec<DirDescendant<T, P>>: AssertEq<Vec<DirDescendant<T, P>>> + Debug,
for<'__trivial> PhantomData<F>: AssertEq<PhantomData<F>> + Debug,
Source§impl<T: Clone, F: FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P>, P: PathType + ?Sized> Clone for DirDescendants<T, F, P>
impl<T: Clone, F: FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P>, P: PathType + ?Sized> Clone for DirDescendants<T, F, P>
Source§impl<T: Debug, F: FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P>, P: PathType + ?Sized> Debug for DirDescendants<T, F, P>
impl<T: Debug, F: FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P>, P: PathType + ?Sized> Debug for DirDescendants<T, F, P>
Source§impl<T, F: FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P>, P: PathType + ?Sized> Default for DirDescendants<T, F, P>
impl<T, F: FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P>, P: PathType + ?Sized> Default for DirDescendants<T, F, P>
Source§impl<T, F: FolderFilter + FolderRecurseFilter + FileFilter> DynamicHasField for DirDescendants<T, F>
impl<T, F: FolderFilter + FolderRecurseFilter + FileFilter> DynamicHasField for DirDescendants<T, F>
Source§fn resolve_path<P: OwnedPathType>(p: P, name: &str) -> P
fn resolve_path<P: OwnedPathType>(p: P, name: &str) -> P
resolve-path only.Self, given the name
passed into the resolve_path! macro.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> From<Vec<DirDescendant<T, P>>> for DirDescendants<T, F, P>
impl<T, F: FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P>, P: PathType + ?Sized> From<Vec<DirDescendant<T, P>>> for DirDescendants<T, F, P>
Source§fn from(descendants: Vec<DirDescendant<T, P>>) -> Self
fn from(descendants: Vec<DirDescendant<T, P>>) -> Self
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<'a, T, F: FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P>, P: PathType + ?Sized> IntoIterator for &'a DirDescendants<T, F, P>
impl<'a, T, F: FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P>, P: PathType + ?Sized> IntoIterator for &'a DirDescendants<T, F, P>
Source§impl<'a, T, F: FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P>, P: PathType + ?Sized> IntoIterator for &'a mut DirDescendants<T, F, P>
impl<'a, T, F: FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P>, P: PathType + ?Sized> IntoIterator for &'a mut DirDescendants<T, F, P>
Source§impl<T, F: FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P>, P: PathType + ?Sized> IntoIterator for DirDescendants<T, F, P>
impl<T, F: FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P>, P: PathType + ?Sized> IntoIterator for DirDescendants<T, F, P>
Source§impl<T: PartialEq, F: PartialEq + FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P>, P: PartialEq + PathType + ?Sized> PartialEq for DirDescendants<T, F, P>
impl<T: PartialEq, F: PartialEq + FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P>, P: PartialEq + PathType + ?Sized> PartialEq for DirDescendants<T, F, P>
Source§impl<'vfs, Vfs: Vfs<'vfs>, T: ReadFrom<'vfs, Vfs>, F: FolderFilter<Vfs::Path> + FolderRecurseFilter<Vfs::Path> + FileFilter<Vfs::Path> + 'vfs> ReadFrom<'vfs, Vfs> for DirDescendants<T, F, Vfs::Path>
impl<'vfs, Vfs: Vfs<'vfs>, T: ReadFrom<'vfs, Vfs>, F: FolderFilter<Vfs::Path> + FolderRecurseFilter<Vfs::Path> + FileFilter<Vfs::Path> + 'vfs> ReadFrom<'vfs, Vfs> for DirDescendants<T, F, Vfs::Path>
Source§impl<'vfs, P: PathType + ?Sized + 'vfs, Vfs: VfsAsync<Path = P> + 'static, T: ReadFromAsync<'vfs, Vfs> + Send + 'static, F: FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P> + 'vfs> ReadFromAsync<'vfs, Vfs> for DirDescendants<T, F, P>
Available on crate feature async only.
impl<'vfs, P: PathType + ?Sized + 'vfs, Vfs: VfsAsync<Path = P> + 'static, T: ReadFromAsync<'vfs, Vfs> + Send + 'static, F: FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P> + 'vfs> ReadFromAsync<'vfs, Vfs> for DirDescendants<T, F, P>
async only.Source§impl<'vfs, Vfs: WriteSupportingVfs<'vfs>, T: WriteTo<'vfs, Vfs> + 'vfs, F: FileFilter<Vfs::Path> + FolderRecurseFilter<Vfs::Path> + FolderFilter<Vfs::Path> + 'vfs> WriteTo<'vfs, Vfs> for DirDescendants<T, F, Vfs::Path>
impl<'vfs, Vfs: WriteSupportingVfs<'vfs>, T: WriteTo<'vfs, Vfs> + 'vfs, F: FileFilter<Vfs::Path> + FolderRecurseFilter<Vfs::Path> + FolderFilter<Vfs::Path> + 'vfs> WriteTo<'vfs, Vfs> for DirDescendants<T, F, Vfs::Path>
Source§impl<'vfs, Vfs: WriteSupportingVfsAsync + 'vfs, T: WriteToAsync<'vfs, Vfs> + Send + 'vfs, F: FileFilter<Vfs::Path> + FolderRecurseFilter<Vfs::Path> + FolderFilter<Vfs::Path> + Send + 'vfs> WriteToAsync<'vfs, Vfs> for DirDescendants<T, F, Vfs::Path>
Available on crate feature async only.
impl<'vfs, Vfs: WriteSupportingVfsAsync + 'vfs, T: WriteToAsync<'vfs, Vfs> + Send + 'vfs, F: FileFilter<Vfs::Path> + FolderRecurseFilter<Vfs::Path> + FolderFilter<Vfs::Path> + Send + 'vfs> WriteToAsync<'vfs, Vfs> for DirDescendants<T, F, Vfs::Path>
async only.Source§impl<'vfs, Vfs: WriteSupportingVfsAsync<Path = P> + 'static, P: ?Sized + PathType, T: WriteToAsyncRef<'vfs, Vfs> + Sync + 'static, F: FileFilter<P> + FolderRecurseFilter<P> + FolderFilter<P> + Sync + 'vfs> WriteToAsyncRef<'vfs, Vfs> for DirDescendants<T, F, P>
Available on crate feature async only.
impl<'vfs, Vfs: WriteSupportingVfsAsync<Path = P> + 'static, P: ?Sized + PathType, T: WriteToAsyncRef<'vfs, Vfs> + Sync + 'static, F: FileFilter<P> + FolderRecurseFilter<P> + FolderFilter<P> + Sync + 'vfs> WriteToAsyncRef<'vfs, Vfs> for DirDescendants<T, F, P>
async only.impl<T, F: FolderFilter<P> + FolderRecurseFilter<P> + FileFilter<P>, P: PathType + ?Sized> StructuralPartialEq for DirDescendants<T, F, P>
Auto Trait Implementations§
impl<T, F, P> Freeze for DirDescendants<T, F, P>where
P: ?Sized,
impl<T, F, P> RefUnwindSafe for DirDescendants<T, F, P>where
F: RefUnwindSafe,
<P as PathType>::PathSegmentOwned: RefUnwindSafe,
<P as PathType>::OwnedPath: RefUnwindSafe,
T: RefUnwindSafe,
P: ?Sized,
impl<T, F, P> Send for DirDescendants<T, F, P>
impl<T, F, P> Sync for DirDescendants<T, F, P>
impl<T, F, P> Unpin for DirDescendants<T, F, P>
impl<T, F, P> UnwindSafe for DirDescendants<T, F, P>where
F: UnwindSafe,
<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<T> DirStructureItem for T
impl<T> DirStructureItem for T
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 moreSource§impl<'data, I> IntoParallelRefMutIterator<'data> for I
impl<'data, I> IntoParallelRefMutIterator<'data> for I
type Iter = <&'data mut I as IntoParallelIterator>::Iter
type Item = <&'data mut I as IntoParallelIterator>::Item
fn par_iter_mut( &'data mut self, ) -> <I as IntoParallelRefMutIterator<'data>>::Iter
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().