|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +HashRust is a CLI file hashing utility written in Rust that supports multiple hash algorithms (MD5, SHA1, SHA2, SHA3, Blake2, Whirlpool, CRC32) with multi-threading capabilities via Rayon. The project uses a modular architecture with separate modules for hashing logic, algorithm types, and CLI processing. |
| 8 | + |
| 9 | +## Common Commands |
| 10 | + |
| 11 | +### Building |
| 12 | +- `cargo build` - Development build |
| 13 | +- `cargo build -r` or `cargo build --release` - Release build (recommended for performance) |
| 14 | + |
| 15 | +### Testing |
| 16 | +- `cargo test` - Run unit tests (located in src/unit_tests.rs) |
| 17 | +- `cargo test --test integration_tests` - Run integration tests |
| 18 | + |
| 19 | +### Code Quality |
| 20 | +- `cargo check` - Fast compilation check without producing binary |
| 21 | +- `cargo clippy` - Run linter with standard warnings |
| 22 | +- `cargo clippy -- -D clippy::all -D clippy::pedantic` - Run pedantic clippy checks (matches .vscode/tasks.json) |
| 23 | +- `cargo fmt` - Format code |
| 24 | + |
| 25 | +### Running |
| 26 | +- `cargo run -- *.txt -a sha3` - Run with file glob and algorithm |
| 27 | +- `cargo run -- --help` - Show help |
| 28 | + |
| 29 | +## Code Architecture |
| 30 | + |
| 31 | +### Module Structure |
| 32 | +- `main.rs` - CLI argument parsing, main worker function, and threading coordination |
| 33 | +- `classes.rs` - Core types: `HashAlgorithm` enum, `OutputEncoding` enum, `ConfigSettings` struct, `BasicHash` wrapper |
| 34 | +- `hasher.rs` - Generic hashing implementation using Digest trait, file I/O optimization for small/large files |
| 35 | +- `crc32.rs` - Custom CRC32 implementation (separate from other hash algorithms) |
| 36 | +- `unit_tests.rs` - Unit test module |
| 37 | + |
| 38 | +### Key Design Patterns |
| 39 | +- Uses Rust's `Digest` trait for generic hash algorithm implementation |
| 40 | +- Multi-threading via Rayon's parallel iterators (`par_iter`) |
| 41 | +- Single-threaded fallback for single files or when explicitly requested |
| 42 | +- Enum-driven algorithm selection with `strum` for string parsing |
| 43 | +- Buffer size optimization: small files (≤32KB) read entirely, larger files use 32KB chunks |
| 44 | + |
| 45 | +### Algorithm Support |
| 46 | +- CRC32 outputs as U32 format only (10-digit zero-padded) |
| 47 | +- All other algorithms support Hex (default), Base64, Base32 encoding |
| 48 | +- Default algorithm is SHA3-256 |
| 49 | + |
| 50 | +### Configuration |
| 51 | +- `ConfigSettings` struct centralizes all CLI options |
| 52 | +- Supports glob patterns with case-sensitive option |
| 53 | +- File input via CLI args or stdin pipe |
| 54 | +- Optional file count limiting |
| 55 | + |
| 56 | +### Error Handling |
| 57 | +- Uses `anyhow` for error propagation |
| 58 | +- Graceful handling of file access errors |
| 59 | +- Validates algorithm/encoding combinations |
| 60 | + |
| 61 | +## Development Notes |
| 62 | + |
| 63 | +### Copilot Instructions Integration |
| 64 | +- Target senior engineers (15+ years experience) |
| 65 | +- Use modern Rust idioms and functional style |
| 66 | +- Keep code concise, avoid unchanged code in suggestions |
| 67 | +- Brief commit messages preferred |
| 68 | + |
| 69 | +### Performance Considerations |
| 70 | +- Multi-threading is default behavior |
| 71 | +- Buffer size optimized for typical file sizes |
| 72 | +- Uses BufReader for efficient file I/O |
| 73 | +- Release builds use LTO and panic=abort for size/speed |
| 74 | + |
| 75 | +## Development Workflow |
| 76 | + |
| 77 | +**IMPORTANT: Always run `cargo fmt` after making any code changes to ensure consistent formatting.** |
0 commit comments