| Crates.io | cargo-rust-unused |
| lib.rs | cargo-rust-unused |
| version | 0.1.0 |
| created_at | 2025-10-19 00:25:31.50718+00 |
| updated_at | 2025-10-19 00:25:31.50718+00 |
| description | A CLI tool for detecting unused code in Rust projects |
| homepage | |
| repository | https://github.com/Dhir0808/cargo-rust-unused |
| max_upload_size | |
| id | 1889781 |
| size | 35,352 |
A CLI tool for detecting unused code in Rust projects. This tool helps you maintain clean and efficient codebases by identifying:
Cargo.tomlsyn for accurate parsingCargo.tomlcoming soon
# Clone the repository
git clone https://github.com/yourusername/cargo-rust-unused
cd cargo-rust-unused
# Build and install locally
cargo install --path .
The tool can be used in two ways:
cargo rust-unused [OPTIONS]
cargo-rust-unused [OPTIONS]
--path <PATH>: Path to the Rust project (default: current directory)--format <FORMAT>: Output format [text|json] (default: text)--include-private: Include private items in the analysis--help: Print help information--version: Print version information# Navigate to your Rust project
cd my-rust-project
# Run the analysis
cargo rust-unused
cargo rust-unused --format json
cargo rust-unused --path ~/projects/my-rust-project
# Save as text
cargo rust-unused > analysis_report.txt
# Save as JSON
cargo rust-unused --format json > analysis_report.json
🔍 Analyzing project...
Unused Dependencies:
- regex
- serde_yaml
Unused Functions:
- fn unused_utility()
- fn deprecated_function()
Unused Modules:
- mod old_features
{
"unused_dependencies": ["regex", "serde_yaml"],
"unused_functions": ["fn unused_utility", "fn deprecated_function"],
"unused_modules": ["mod old_features"]
}
You can integrate the tool into your CI/CD pipeline. Here's an example GitHub Actions workflow:
name: Code Analysis
on: [push, pull_request]
jobs:
unused-code-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install cargo-rust-unused
run: cargo install --path .
- name: Run Analysis
run: |
cargo rust-unused --format json > analysis.json
- name: Check Results
run: |
if [ "$(jq '.unused_dependencies | length' analysis.json)" -gt 0 ]; then
echo "Warning: Found unused dependencies!"
exit 1
fi
Regular Usage:
Handling Results:
False Positives:
#[allow(dead_code)] for intentionally unused itemsTool Not Finding Files:
Cargo.toml existssrc directory existsIncorrect Results:
--include-private flagError: Not a Cargo project: no Cargo.toml found
Solution: Run from a Rust project directory
Error: No src directory found
Solution: Create src directory or check path
Contributions are welcome! Please feel free to submit a Pull Request. Here's how you can contribute:
git checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.