4 releases
Uses new Rust 2024
new 0.0.4 | Mar 30, 2025 |
---|---|
0.0.3 | Mar 30, 2025 |
0.0.2 | Mar 30, 2025 |
0.0.1 | Mar 30, 2025 |
#37 in #find
10KB
147 lines
up_finder
A lightweight Rust library for finding files or directories upward in the directory tree.
Features
- Find files or directories in the current working directory and all parent directories
- Support for finding a single file or multiple files
- High-performance HashMap implementation using
rustc-hash
- Concise builder API implemented with
typed-builder
- No external system dependencies, pure Rust implementation
Installation
Add the following dependency to your Cargo.toml
file:
[dependencies]
up_finder = "0.0.1"
Usage Examples
Find a Single File
use up_finder::{UpFinder, FindUpKind};
// Create a UpFinder instance, default is to find files
let find_up = UpFinder::builder()
.cwd(".") // Start from the current directory
.kind(FindUpKind::File) // Optional, finding files is the default
.build();
// Find package.json files upward
let paths = find_up.find_up("package.json");
// Print all found paths
println!("{:#?}", paths);
Find Multiple Files
use up_finder::{UpFinder, FindUpKind};
// Create a UpFinder instance
let find_up = UpFinder::builder()
.cwd("./src") // Start from the src directory
.build();
// Find multiple files simultaneously
let paths = find_up.find_up_multi(&["package.json", ".gitignore", "Cargo.toml"]);
// Result is a HashMap with file names as keys and lists of found paths as values
for (file_name, file_paths) in paths {
println!("Found {} {} files:", file_paths.len(), file_name);
for path in file_paths {
println!(" - {}", path.display());
}
}
Find Directories
use up_finder::{UpFinder, FindUpKind};
// Create a UpFinder instance for finding directories
let find_up = UpFinder::builder()
.cwd(".")
.kind(FindUpKind::Dir) // Set to find directories
.build();
// Find "node_modules" directories upward
let paths = find_up.find_up("node_modules");
println!("{:#?}", paths);
API Documentation
For detailed API documentation, visit docs.rs/up_finder.
Contribution
Issues and pull requests are welcome!
License
This project is licensed under the MIT License.
Dependencies
~260–710KB
~16K SLoC