treewalk/walk/utils.rs
1#[allow(unused_imports)]
2use std::path::PathBuf;
3/// returns [`Vec`] of [`PathBuf`]s with which to operate on
4/// # Examples
5///
6/// ```
7/// use std::path::PathBuf;
8/// use treewalk::walk::utils;
9/// let test_vec: Vec<PathBuf> = vec!["./foo", "./bar"]
10/// .iter()
11/// .map(|path| PathBuf::from(path))
12/// .collect();
13/// assert_eq!(test_vec, utils::tree!["./foo", "./bar"]);
14/// ```
15///
16#[macro_export]
17macro_rules! tree {
18 ( $( $x:expr ),* ) => {
19 {
20 let mut temp_vec: Vec<PathBuf> = Vec::new();
21 $(
22 temp_vec.push(PathBuf::from($x));
23 )*
24 temp_vec
25 }
26 };
27}
28pub use tree;
29
30pub fn num_dirs(children: &Vec<PathBuf>) -> usize {
31 children.iter().filter(|path| path.is_dir()).count()
32}
33
34pub fn num_files(children: &Vec<PathBuf>) -> usize {
35 children.iter().filter(|path| path.is_file()).count()
36}