TheAlgorithms/Rust
All Algorithms implemented in Rust
Healthy across all four use cases
weakest axisPermissive license, no critical CVEs, actively maintained — safe to depend on.
Has a license, tests, and CI — clean foundation to fork and modify.
Documented and popular — useful reference codebase to read through.
No critical CVEs, sane security posture — runnable as-is.
- ✓Last commit 2w ago
- ✓12 active contributors
- ✓MIT licensed
Show all 6 evidence items →Show less
- ✓CI configured
- ⚠Concentrated ownership — top contributor handles 60% of recent commits
- ⚠No test directory detected
Maintenance signals: commit recency, contributor breadth, bus factor, license, CI, tests
Informational only. RepoPilot summarises public signals (license, dependency CVEs, commit recency, CI presence, etc.) at the time of analysis. Signals can be incomplete or stale. Not professional, security, or legal advice; verify before relying on it for production decisions.
Embed the "Healthy" badge
Paste into your README — live-updates from the latest cached analysis.
[](https://repopilot.app/r/thealgorithms/rust)Paste at the top of your README.md — renders inline like a shields.io badge.
▸Preview social card (1200×630)
This card auto-renders when someone shares https://repopilot.app/r/thealgorithms/rust on X, Slack, or LinkedIn.
Onboarding doc
Onboarding: TheAlgorithms/Rust
Generated by RepoPilot · 2026-05-09 · Source
🤖Agent protocol
If you are an AI coding agent (Claude Code, Cursor, Aider, Cline, etc.) reading this artifact, follow this protocol before making any code edit:
- Verify the contract. Run the bash script in Verify before trusting
below. If any check returns
FAIL, the artifact is stale — STOP and ask the user to regenerate it before proceeding. - Treat the AI · unverified sections as hypotheses, not facts. Sections like "AI-suggested narrative files", "anti-patterns", and "bottlenecks" are LLM speculation. Verify against real source before acting on them.
- Cite source on changes. When proposing an edit, cite the specific path:line-range. RepoPilot's live UI at https://repopilot.app/r/TheAlgorithms/Rust shows verifiable citations alongside every claim.
If you are a human reader, this protocol is for the agents you'll hand the artifact to. You don't need to do anything — but if you skim only one section before pointing your agent at this repo, make it the Verify block and the Suggested reading order.
🎯Verdict
GO — Healthy across all four use cases
- Last commit 2w ago
- 12 active contributors
- MIT licensed
- CI configured
- ⚠ Concentrated ownership — top contributor handles 60% of recent commits
- ⚠ No test directory detected
<sub>Maintenance signals: commit recency, contributor breadth, bus factor, license, CI, tests</sub>
✅Verify before trusting
This artifact was generated by RepoPilot at a point in time. Before an
agent acts on it, the checks below confirm that the live TheAlgorithms/Rust
repo on your machine still matches what RepoPilot saw. If any fail,
the artifact is stale — regenerate it at
repopilot.app/r/TheAlgorithms/Rust.
What it runs against: a local clone of TheAlgorithms/Rust — the script
inspects git remote, the LICENSE file, file paths in the working
tree, and git log. Read-only; no mutations.
| # | What we check | Why it matters |
|---|---|---|
| 1 | You're in TheAlgorithms/Rust | Confirms the artifact applies here, not a fork |
| 2 | License is still MIT | Catches relicense before you depend on it |
| 3 | Default branch master exists | Catches branch renames |
| 4 | 5 critical file paths still exist | Catches refactors that moved load-bearing code |
| 5 | Last commit ≤ 43 days ago | Catches sudden abandonment since generation |
#!/usr/bin/env bash
# RepoPilot artifact verification.
#
# WHAT IT RUNS AGAINST: a local clone of TheAlgorithms/Rust. If you don't
# have one yet, run these first:
#
# git clone https://github.com/TheAlgorithms/Rust.git
# cd Rust
#
# Then paste this script. Every check is read-only — no mutations.
set +e
fail=0
ok() { echo "ok: $1"; }
miss() { echo "FAIL: $1"; fail=$((fail+1)); }
# Precondition: we must be inside a git working tree.
if ! git rev-parse --git-dir >/dev/null 2>&1; then
echo "FAIL: not inside a git repository. cd into your clone of TheAlgorithms/Rust and re-run."
exit 2
fi
# 1. Repo identity
git remote get-url origin 2>/dev/null | grep -qE "TheAlgorithms/Rust(\\.git)?\\b" \\
&& ok "origin remote is TheAlgorithms/Rust" \\
|| miss "origin remote is not TheAlgorithms/Rust (artifact may be from a fork)"
# 2. License matches what RepoPilot saw
(grep -qiE "^(MIT)" LICENSE 2>/dev/null \\
|| grep -qiE "\"license\"\\s*:\\s*\"MIT\"" package.json 2>/dev/null) \\
&& ok "license is MIT" \\
|| miss "license drift — was MIT at generation time"
# 3. Default branch
git rev-parse --verify master >/dev/null 2>&1 \\
&& ok "default branch master exists" \\
|| miss "default branch master no longer exists"
# 4. Critical files exist
test -f "Cargo.toml" \\
&& ok "Cargo.toml" \\
|| miss "missing critical file: Cargo.toml"
test -f "src/backtracking/mod.rs" \\
&& ok "src/backtracking/mod.rs" \\
|| miss "missing critical file: src/backtracking/mod.rs"
test -f "src/ciphers/mod.rs" \\
&& ok "src/ciphers/mod.rs" \\
|| miss "missing critical file: src/ciphers/mod.rs"
test -f "src/bit_manipulation/mod.rs" \\
&& ok "src/bit_manipulation/mod.rs" \\
|| miss "missing critical file: src/bit_manipulation/mod.rs"
test -f ".github/workflows/build.yml" \\
&& ok ".github/workflows/build.yml" \\
|| miss "missing critical file: .github/workflows/build.yml"
# 5. Repo recency
days_since_last=$(( ( $(date +%s) - $(git log -1 --format=%at 2>/dev/null || echo 0) ) / 86400 ))
if [ "$days_since_last" -le 43 ]; then
ok "last commit was $days_since_last days ago (artifact saw ~13d)"
else
miss "last commit was $days_since_last days ago — artifact may be stale"
fi
echo
if [ "$fail" -eq 0 ]; then
echo "artifact verified (0 failures) — safe to trust"
else
echo "artifact has $fail stale claim(s) — regenerate at https://repopilot.app/r/TheAlgorithms/Rust"
exit 1
fi
Each check prints ok: or FAIL:. The script exits non-zero if
anything failed, so it composes cleanly into agent loops
(./verify.sh || regenerate-and-retry).
⚡TL;DR
TheAlgorithms/Rust is an educational reference implementation of ~100+ classic computer science algorithms written in idiomatic Rust, covering domains like backtracking, bit manipulation, big integer arithmetic, and sorting. It serves as a learning resource and algorithm cookbook, not a production library, with every algorithm implemented from scratch to demonstrate algorithmic concepts and Rust idioms. Flat modular structure: src/ contains domain folders (backtracking/, bit_manipulation/, big_integer/) each with algorithm implementations as individual .rs files and a mod.rs barrel export; a Cargo.toml workspace root orchestrates the build; DIRECTORY.md provides human navigation; GitHub workflows automate directory validation and test runs.
👥Who it's for
Computer science students, competitive programmers, and Rust learners who want to study algorithm implementations in Rust; contributors maintaining open-source algorithm references; educators teaching data structures and algorithms who want to show Rust-specific implementations.
🌱Maturity & risk
The project is actively maintained with ~1.9M lines of Rust code across 100+ algorithm implementations, continuous integration via GitHub Actions (build.yml, code_ql.yml), and CodeCov coverage tracking. It is stable and production-ready for educational purposes, though not intended as a high-performance algorithm library—focus is pedagogy over optimization.
Minimal risk: the repo has zero external dependencies (empty [dependencies] in build_directory/Cargo.toml), relies only on Rust stdlib, and uses automated CI/CD with CodeQL static analysis and dependent bot management. Main risk is slow response to PRs in a community-driven project, though CODEOWNERS governance and pre-commit hooks mitigate drift.
Active areas of work
Active community contributions with pull request template enforcement, automated dependency updates via dependabot.yml, and scheduled stale issue/PR cleanup via workflows/stale.yml. Directory and build validation workflows (directory_workflow.yml) run on each commit to maintain consistency.
🚀Get running
git clone https://github.com/TheAlgorithms/Rust.git
cd Rust
cargo build
cargo test
Daily commands:
cargo build # Compile all algorithms
cargo test # Run all unit tests
cargo test --lib # Run library tests only
cargo clippy # Run linter
🗺️Map of the codebase
Cargo.toml— Root manifest defining the workspace structure and shared dependencies for all algorithm modules.src/backtracking/mod.rs— Module entry point aggregating all backtracking algorithms; essential for understanding pattern-based organization.src/ciphers/mod.rs— Central registry of cryptographic implementations; shows how the codebase organizes related algorithms.src/bit_manipulation/mod.rs— Module entry point for bit-level operations; demonstrates utility function organization strategy..github/workflows/build.yml— CI/CD pipeline definition that validates all algorithm implementations; critical for understanding testing requirements.CONTRIBUTING.md— Contributor guidelines documenting code style, module structure, and PR expectations for new algorithms.DIRECTORY.md— Comprehensive index of all algorithms organized by category; essential reference for navigating 478 files.
🧩Components & responsibilities
- Algorithm Module (src/[category]/*.rs) (Pure Rust (no external crates for core logic)) — Implements a single algorithm with public function(s), comprehensive inline comments, and #[cfg(test)] unit tests. Responsible for correctness and code clarity.
- Failure mode: If algorithm is incorrect or inefficient, test failures caught by CI
🛠️How to make changes
Add a New Algorithm
- Choose or create the appropriate module directory (e.g., src/sorting/, src/dynamic_programming/). Create a new .rs file with a descriptive name (snake_case). (
src/[category]/new_algorithm.rs) - Implement the algorithm with public function(s), comprehensive comments, and docstring examples. (
src/[category]/new_algorithm.rs) - Add unit tests or integration tests at the bottom of the file or in a dedicated tests/ directory using #[cfg(test)]. (
src/[category]/new_algorithm.rs) - Register the module in the parent module's mod.rs file (e.g., src/[category]/mod.rs) using pub mod new_algorithm; (
src/[category]/mod.rs) - Update the root src/lib.rs or verify module hierarchy is properly exported so the algorithm is public. (
src/lib.rs) - Push to a feature branch and open a PR; CI pipeline validates compilation, tests, and clippy lints. DIRECTORY.md is auto-generated on merge. (
.github/workflows/build.yml)
Add a New Algorithm Category
- Create a new directory under src/ (e.g., src/quantum_algorithms/) with an empty mod.rs file. (
src/new_category/mod.rs) - Declare the new module in the root lib.rs using pub mod new_category; (
src/lib.rs) - Add your first algorithm file to the new directory and export it in the mod.rs. (
src/new_category/algorithm1.rs) - Commit and push; the build workflow and DIRECTORY.md generation will automatically include the new category. (
.github/workflows/scripts/build_directory/src/main.rs)
Fix or Improve an Existing Algorithm
- Locate the algorithm file in DIRECTORY.md or via file search (e.g., src/sorting/bubble_sort.rs). (
DIRECTORY.md) - Edit the algorithm implementation, optimize the logic, improve comments, or add edge-case tests. (
src/[category]/algorithm_name.rs) - Run local tests: cargo test [algorithm_name] to validate changes before pushing. (
Cargo.toml) - Push to a PR branch; CI ensures all tests pass, clippy passes, and code coverage is reported. (
.github/workflows/build.yml)
🔧Why these technologies
- Rust — Memory safety without garbage collection; compile-time correctness guarantees; excellent performance for algorithm benchmarking; strong type system prevents entire classes of bugs.
- Cargo workspace (single Cargo.toml) — Unifies all 478 algorithm files under one build system; shared dependencies and consistent compilation; simplified CI/CD configuration.
- GitHub Actions CI/CD — Automated validation on every PR; ensures code quality (Clippy), correctness (tests), and coverage tracking; gates merges to main.
- Clippy linter (clippy.toml) — Enforces idiomatic Rust patterns; catches performance anti-patterns and common mistakes; maintains code consistency across 200+ implementations.
⚖️Trade-offs already made
-
Single monorepo with 478 files in src/ organized by algorithm category
- Why: Simplifies discoverability (DIRECTORY.md index), shared CI/CD, and unified code style; enables contributors to browse related algorithms easily.
- Consequence: Large repo size; longer initial clone/build; each PR touches shared infrastructure; requires discipline to avoid cross-module coupling.
-
Auto-generated DIRECTORY.md instead of manual maintenance
- Why: Prevents stale documentation; ensures directory always reflects actual code; build_directory script enforces naming conventions.
- Consequence: Directory structure must follow strict file naming conventions; scripts may break if conventions are violated; less flexibility in documentation organization.
-
Comprehensive unit tests within each .rs file using #[cfg(test)]
- Why: Keeps algorithm implementation and tests co-located; minimal test boilerplate; CI validates correctness on every PR.
- Consequence: Algorithm files are longer; test discovery is file-local rather than centralized; harder to run cross-module test suites.
-
No external cryptography or numeric library dependencies (e.g., no OpenSSL, no rug)
- Why: Educational purpose: implementations must be standalone and readable; students learn fundamentals, not black-box APIs.
- Consequence: Cipher and big-integer implementations are slower than production libraries; manual security is error-prone; larger code footprint.
🚫Non-goals (don't propose these)
- Not a production-grade library: algorithms prioritize clarity and educational value over performance, security, and API stability.
- Does not provide external API or network service: purely a local Rust crate for studying algorithms.
- Not a formal algorithm textbook: code structure follows implementation patterns, not mathematical proof or complexity analysis documentation.
- No version stability or semantic versioning guarantee: this is an educational open-source project with frequent breaking changes.
🪤Traps & gotchas
No hidden environment variables or external service dependencies. Key gotchas: (1) DIRECTORY.md must be manually updated for new algorithms or directory_workflow.yml will fail the build, (2) Clippy warnings are enforced by CI—run cargo clippy --all-targets --all-features locally before pushing, (3) Tests must be comprehensive; the repo uses codecov.io integration, so low test coverage may block merges, (4) Pre-commit hook in git_hooks/pre-commit may reject commits if not installed properly—follow CONTRIBUTING.md setup.
🏗️Architecture
💡Concepts to learn
- Backtracking — Backtracking is a core algorithmic pattern implemented across multiple files (n_queens.rs, sudoku.rs, hamiltonian_cycle.rs) that solves constraint satisfaction problems via systematic search and pruning—essential for learning state-space exploration.
- Bit Manipulation — The bit_manipulation/ directory shows how to solve problems via bitwise operations (gray code, counting trailing zeros, power-of-two detection), critical for optimization and low-level algorithm design.
- Graph Coloring — Implemented in src/backtracking/graph_coloring.rs, this NP-complete problem demonstrates how backtracking handles graph constraint problems; foundational for scheduling and register allocation algorithms.
- Knight's Tour — A Hamiltonian path problem on a chessboard (src/backtracking/knight_tour.rs) that illustrates how to explore all moves efficiently and detect dead ends—classic example of backtracking with heuristics.
- Polynomial Evaluation (Poly1305) — The src/big_integer/poly1305.rs implementation demonstrates polynomial MAC construction used in cryptography; shows how big integer arithmetic underpins security algorithms.
- Gray Code — Binary reflected Gray code (src/bit_manipulation/n_bits_gray_code.rs) is a sequence where consecutive values differ by exactly one bit—essential for error-tolerant encoding and Hamiltonian paths on hypercubes.
- Hamiltonian Cycle — A NP-complete graph problem (src/backtracking/hamiltonian_cycle.rs) requiring exhaustive backtracking search; demonstrates computational complexity and why approximation algorithms matter in practice.
🔗Related repos
TheAlgorithms/Python— Sister repo in the same organization implementing the same algorithms in Python; useful for comparing implementations across languages.TheAlgorithms/JavaScript— Another sister repo in the same organization; shows algorithm implementations in JavaScript for web-focused learners.rust-lang/rust-clippy— The Clippy linter tool used throughout this repo; understanding Clippy rules helps contributors write idiomatic Rust code.jwasham/coding-interview-university— Comprehensive study guide for algorithms and data structures that pairs well with this repo's implementations as hands-on practice material.algoexpert-io/algoexpert-opensource— Algorithm tutorial repository; complementary resource for learners wanting both explanation and Rust implementation of classic problems.
🪄PR ideas
To work on one of these in Claude Code or Cursor, paste:
Implement the "<title>" PR idea from CLAUDE.md, working through the checklist as the task list.
Add comprehensive unit tests for cipher implementations
The src/ciphers directory contains many cryptographic implementations (AES, ChaCha, Diffie-Hellman, etc.) but there's no evidence of corresponding test files. Ciphers are security-critical code that require rigorous testing with known test vectors. This would improve code reliability and help prevent subtle bugs in cryptographic implementations.
- [ ] Create src/ciphers/tests directory with test modules
- [ ] Add test_vectors.rs with known plaintext/ciphertext pairs for each cipher (AES, Caesar, Base64, etc.)
- [ ] Add unit tests in each cipher file testing edge cases (empty input, boundary values, special characters)
- [ ] Ensure tests pass in build.yml workflow and contribute to code coverage
Create integration tests for algorithm modules with cross-module dependencies
The repo has many algorithm categories (backtracking, bit_manipulation, big_integer, etc.) but lacks integration tests that verify algorithms work correctly when combined. For example, big_integer fast_factorial could be tested with large inputs, or backtracking algorithms tested against known solutions. This validates real-world usage patterns.
- [ ] Create tests/ directory at repo root for integration tests
- [ ] Add tests/backtracking_integration.rs testing sudoku, n_queens, hamiltonian_cycle with known solvable inputs
- [ ] Add tests/big_integer_integration.rs testing fast_factorial and multiply with large numbers against expected results
- [ ] Add tests/bit_manipulation_integration.rs testing gray_code, bit counting, and power-of-two detection chains
- [ ] Verify tests are included in build.yml workflow
Add benchmark suite for performance-critical algorithms
With algorithms spanning backtracking, sorting, and big integer operations, there's no benches/ directory to track performance. This is valuable for maintaining algorithmic efficiency as the codebase grows and for helping contributors understand which implementations are optimized.
- [ ] Create benches/ directory following Cargo conventions
- [ ] Add benches/backtracking_benchmarks.rs benchmarking n_queens, sudoku, and knight_tour with various input sizes
- [ ] Add benches/big_integer_benchmarks.rs benchmarking fast_factorial and multiply performance
- [ ] Add benches/bit_manipulation_benchmarks.rs benchmarking gray_code and counting_bits
- [ ] Document how to run benchmarks in CONTRIBUTING.md with
cargo benchcommand
🌿Good first issues
- Implement missing unit tests for src/big_integer/poly1305.rs and src/big_integer/fast_factorial.rs—these algorithms exist but have minimal test coverage visible in the repo, increasing the value of comprehensive test additions.
- Add documentation comments and examples to src/backtracking/sudoku.rs and src/backtracking/rat_in_maze.rs following Rust doc-test conventions—these complex algorithms lack inline explanations that would help learners understand the backtracking strategy.
- Create a missing sorting algorithms module (src/sorting/) with implementations of quicksort, mergesort, and heapsort, then update DIRECTORY.md accordingly—this fills an obvious gap in the algorithms taxonomy visible in the current src/ structure.
⭐Top contributors
Click to expand
Top contributors
- @AliAlimohammadi — 60 commits
- @vil02 — 11 commits
- @dependabot[bot] — 7 commits
- @Dcyaprogrammer — 6 commits
- @0xprincedev — 5 commits
📝Recent commits
Click to expand
Recent commits
c4c395f— feat: add job sequencing algorithm (#1038) (AliAlimohammadi)3bccfa8— feat: Add decoupled weight decay (AdamW) to Adam optimizer (#1037) (AliAlimohammadi)e08f5a5— feat: add Strand Sort and fixsort_utilsunused import warnings (#1036) (AliAlimohammadi)2cb9392— feat: add Fletcher checksum to hashing (#1034) (AliAlimohammadi)6e42c38— feat: move hash functions to dedicated hashing module and add MD5 (#1033) (AliAlimohammadi)d3c9028— chore(deps): bump codecov/codecov-action from 5 to 6 in /.github/workflows (#1031) (dependabot[bot])6166ca0— feat: add SHA-1 hash function implementation (#1030) (AliAlimohammadi)3bad194— feat: add SHA-2 family of hash functions (#1032) (AliAlimohammadi)1c7738e— feat: add Peak Signal-to-Noise Ratio (PSNR) to compression (#1028) (AliAlimohammadi)88a00a6— chore: resolve and suppress new warnings (#1029) (vil02)
🔒Security observations
The TheAlgorithms/Rust repository demonstrates generally good security posture for an educational algorithms collection. Primary findings are low-severity concerns related to the educational nature of cryptographic implementations and the need for clearer security disclaimers. No critical vulnerabilities, hardcoded secrets, injection risks, or infrastructure misconfigurations were identified. The codebase lacks external dependencies (per the visible Cargo.toml), reducing supply chain attack surface. Recommendations focus on adding explicit warnings about cryptographic implementations not being production-ready and implementing dependency security scanning in CI/CD pipelines.
- Low · Cryptographic Implementations in Algorithm Repository —
src/ciphers/ directory (aes.rs, rsa_cipher.rs, chacha.rs, salsa.rs, tea.rs, etc.). The repository contains multiple cryptographic cipher implementations (AES, RSA, ChaCha, Salsa, TEA, etc.) that appear to be educational/reference implementations rather than production-grade cryptographic libraries. While this is typical for an algorithms repository, these implementations may not have undergone rigorous security audits and should not be used in production security contexts. Fix: Add clear documentation in README and cipher module files explicitly stating these are educational implementations. Recommend users rely on established cryptographic libraries (e.g., ring, rustls, RustCrypto) for production use. Consider adding security warnings in cipher module documentation. - Low · Potential Integer Overflow in Big Integer Operations —
src/big_integer/ directory (fast_factorial.rs, multiply.rs). The big_integer module (fast_factorial.rs, multiply.rs) performs arithmetic operations that could potentially overflow if not carefully bounded. While Rust's type system provides some protection, edge cases in factorial and multiplication algorithms warrant careful review. Fix: Add comprehensive input validation and bounds checking. Include unit tests with edge cases (very large numbers, zero, negative inputs). Use checked arithmetic operations (checked_mul, checked_add) where applicable. Document maximum safe input sizes. - Low · No Dependency Pinning Strategy Visible —
Cargo.toml (root level). The Cargo.toml for the build_directory script has no dependencies specified, which is good. However, the main repository's Cargo.toml should implement a dependency pinning/locking strategy to ensure reproducible builds and prevent supply chain attacks. Fix: Implement Cargo.lock file in version control for reproducible builds. Consider using cargo-audit in CI/CD pipeline to regularly check for known vulnerabilities in dependencies. Review and pin dependency versions explicitly where security is critical. - Low · XOR Cipher Implementation Present —
src/ciphers/xor.rs. The ciphers module includes a basic XOR cipher (xor.rs), which is cryptographically weak and should never be used for real security purposes. Educational context is assumed, but this could mislead users unfamiliar with cryptography. Fix: Add prominent warnings in the XOR cipher implementation and documentation explicitly stating it provides no real cryptographic security. Reference appropriate secure alternatives in comments.
LLM-derived; treat as a starting point, not a security audit.
👉Where to read next
- Open issues — current backlog
- Recent PRs — what's actively shipping
- Source on GitHub
Generated by RepoPilot. Verdict based on maintenance signals — see the live page for receipts. Re-run on a new commit to refresh.