1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
/*!
# Dowser
[](https://docs.rs/dowser/)
[](https://github.com/Blobfolio/dowser/blob/master/CHANGELOG.md)<br>
[](https://crates.io/crates/dowser)
[](https://github.com/Blobfolio/dowser/actions)
[](https://deps.rs/repo/github/blobfolio/dowser)<br>
[](https://en.wikipedia.org/wiki/WTFPL)
[](https://github.com/Blobfolio/dowser/issues)
[`Dowser`] is a(nother) fast, recursive file-finding library for Unix/Rust. It differs from [`Walkdir`](https://crates.io/crates/walkdir) and kin in a number of ways:
* It is not limited to one root; any number of file and directory paths can be loaded and traversed en masse;
* Symlinks and hidden directories are followed like any other, including across devices;
* Matching file paths are canonicalized and deduped before yielding;
If those things sound nice, this library might be a good fit.
On the other hand, [`Dowser`] is optimized for _file_ searching; the iterator crawls but does not yield directory paths, which could be bad if you need those too. Haha.
## Installation
Add `dowser` to your `dependencies` in `Cargo.toml`, like:
```text,ignore
[dependencies]
dowser = "0.6.*"
```
## Example
All you need to do is chain [`Dowser::default`] with one or more of the following seed methods:
* [`Dowser::with_path`] / [`Dowser::with_paths`]
* [`Dowser::without_path`] / [`Dowser::without_paths`]
From there, you can apply any [`Iterator`](std::iter::Iterator) methods you want, or immediately collect the results using [`Dowser::into_vec`] or [`Dowser::into_vec_filtered`].
```
use dowser::Dowser;
use std::path::PathBuf;
// Return all files under "/usr/share/man".
let files1: Vec::<PathBuf> = Dowser::default()
.with_path("/usr/share/man")
.collect();
// Same as above, but slightly faster.
let files2: Vec::<PathBuf> = Dowser::default()
.with_path("/usr/share/man")
.into_vec();
assert_eq!(files1.len(), files2.len());
// Return only Gzipped files using callback filter.
let files1: Vec::<PathBuf> = Dowser::default()
.with_path("/usr/share/man")
.filter(|p|
p.extension().map_or(
false,
|e| e.eq_ignore_ascii_case("gz")
)
)
.collect();
// Same as above, but slightly faster.
let files2: Vec::<PathBuf> = Dowser::default()
.with_path("/usr/share/man")
.into_vec_filtered(|p|
p.extension().map_or(
false,
|e| e.eq_ignore_ascii_case("gz")
)
);
assert_eq!(files1.len(), files2.len());
```
*/
#![forbid(unsafe_code)]
#![warn(
clippy::filetype_is_file,
clippy::integer_division,
clippy::integer_division,
clippy::needless_borrow,
clippy::nursery,
clippy::pedantic,
clippy::perf,
clippy::suboptimal_flops,
clippy::unneeded_field_pattern,
macro_use_extern_crate,
missing_copy_implementations,
missing_debug_implementations,
missing_docs,
non_ascii_idents,
trivial_casts,
trivial_numeric_casts,
unreachable_pub,
unused_crate_dependencies,
unused_extern_crates,
unused_import_braces,
)]
#![allow(clippy::module_name_repetitions)] // This is fine.
mod entry;
mod ext;
mod iter;
pub(crate) use entry::Entry;
pub use ext::Extension;
pub use iter::Dowser;