diff options
author | Charles Samborski <demurgos@demurgos.net> | 2020-02-21 18:16:16 +0100 |
---|---|---|
committer | Charles Samborski <demurgos@demurgos.net> | 2020-02-21 18:16:16 +0100 |
commit | 34a80ec2333d7334eafd0785b283e883e55a2d81 (patch) | |
tree | efca77738f76a3146877e0b87c85a29ec59809a7 | |
parent | fb1dc9501087160de86f8ee634dd48f237764d59 (diff) |
Make `deduplicate_dirs` generic
This commit updates the signature of `deduplicate_dirs` to allow passing any type compatible with `Path` instead of requiring `&str`.
This change aligns the API with Rust's standard library, which uses `AsRef<Path>` for its FS functions.
This is an extra feature and should not break any existing code since `&str` implements `AsRef<Path>`.
-rw-r--r-- | src/lib.rs | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -217,10 +217,10 @@ impl Ord for Fileinfo{ /// let directories = vec!["/home/jon", "/home/doe"]; /// let (files, errors) = ddh::deduplicate_dirs(directories); /// ``` -pub fn deduplicate_dirs(search_dirs: Vec<&str>) -> (Vec<Fileinfo>, Vec<(PathBuf, std::io::Error)>){ +pub fn deduplicate_dirs<P: AsRef<Path> + Sync>(search_dirs: Vec<P>) -> (Vec<Fileinfo>, Vec<(PathBuf, std::io::Error)>){ let (sender, receiver) = channel(); search_dirs.par_iter().for_each_with(sender, |s, search_dir| { - traverse_and_spawn(Path::new(&search_dir), s.clone()); + traverse_and_spawn(search_dir.as_ref(), s.clone()); }); let mut files_of_lengths: IntMap<u64, Vec<Fileinfo>> = IntMap::default(); let mut errors = Vec::new(); |