Expand description
FsTree
iterators.
Iterators for FsTree
.
Iterators traverse in Depth-First Order.
There are three FsTree
methods for creating an iterator:
Iter
from.iter()
yields(&FsTree, PathBuf)
.NodesIter
from.nodes()
yields&FsTree
.PathsIter
from.paths()
yieldsPathBuf
.
The yielded PathBuf
s correspond to the full relative path to the current node, which is the
result of concatenating the paths of every parent, and the current node.
Examples:
use fs_tree::tree;
use std::path::PathBuf;
let tree = tree! {
dir: {
file1
file2
file3
}
};
let mut paths = tree.paths();
assert_eq!(paths.next(), Some(PathBuf::from(""))); // Root can be skipped with `.min_depth(1)`
assert_eq!(paths.next(), Some(PathBuf::from("dir")));
assert_eq!(paths.next(), Some(PathBuf::from("dir/file1")));
assert_eq!(paths.next(), Some(PathBuf::from("dir/file2")));
assert_eq!(paths.next(), Some(PathBuf::from("dir/file3")));
assert_eq!(paths.next(), None);
let mut nodes = tree.nodes();
assert_eq!(nodes.next(), Some(&tree));
assert_eq!(nodes.next(), Some(&tree["dir"]));
assert_eq!(nodes.next(), Some(&tree["dir/file1"]));
assert_eq!(nodes.next(), Some(&tree["dir/file2"]));
assert_eq!(nodes.next(), Some(&tree["dir/file3"]));
assert_eq!(nodes.next(), None);
Structs
- Tree iterator.
- Tree nodes iterator.
- Iterator for each path inside of the recursive struct