Dowser

Documentation crates.io

[Dowser] is a(nother) fast, multi-threaded, recursive file-finding library for Unix/Rust. It differs from Walkdir and kin in a number of ways:

If those things sound nice, this library might be a good fit.

On the other hand, [Dowser] is optimized for just one particular type of searching:

Depending on your needs, those limitations could be bad, in which case something like Walkdir might make more sense.

Installation

Add dowser to your dependencies in Cargo.toml, like:

[dependencies] dowser = "0.1.*"

Features

| Feature | Description | | ------- | ----------- | | regexp | Enable the [Dowser::with_regex] method, which allows for matching file paths (as bytes) against a regular expression. |

To use this feature, alter the Cargo.toml bit to read:

[dependencies.dowser] version = "0.1.*" features = [ "regexp" ]

Example

This crate comes with two ways to find files. If you already have the full list of starting path(s) and just want all the files that exist under them, use the [dowse] method:

```rust use std::path::PathBuf;

let paths = [ "/path/one", "/path/two", "/path/three" ]; let files: Vec = dowser::dowse(&paths); ```

If you need to load starting paths multiple times, or want to filter the results, you can use the full [Dowser] struct instead. It follows a basic builder pattern, so you can just chain your way to an answer:

```rust use dowser::Dowser; use std::{ os::unix::ffi::OsStrExt, path::{Path, PathBuf}, };

// Return all files under "/usr/share/man". let res: Vec = Dowser::default() .with_path("/usr/share/man") .build();

// Return only Gzipped files, using a regular expression. // This requires the "regexp" feature. let res: Vec = Dowser::default() .withregex(r"(?i)[^/]+.gz$") // Filter before adding paths! .withpath("/usr/share/man") .build();

// The same thing, done manually. let res: Vec = Dowser::default() .withfilter(|p: &Path| p.extension() .mapor( false, |e| e.asbytes().eqignoreasciicase(b"gz") ) ) // Again, filter before adding paths! .with_path("/usr/share/man") .build(); ```

If you want to easily bubble an error in cases where no files are found, you can use the [std::convert::TryFrom] trait (instead of calling [Dowser::build]), like:

```rust use dowser::Dowser; use std::convert::TryFrom;

let out = Vec::::tryfrom( Dowser::default().withpath("/usr/share/man") ) .maperr(|| YourErrorHere)?; ```

License

See also: CREDITS.md

Copyright © 2021 Blobfolio, LLC <hello@blobfolio.com>

This work is free. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004

Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>

Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.