A Rust learning project implementing classic algorithms including factorial and Fibonacci calculations.
- Factorial: Both iterative and recursive implementations
- Fibonacci: Both iterative and recursive implementations
- Prime Numbers: Check if a number is prime
git clone <repository-url>
cd rust-xp
cargo build --releaseThe unified command-line interface provides access to all algorithms:
# Factorial (iterative by default)
cargo run -- fac 5
./target/release/rust-xp fac 5
# Factorial (recursive)
cargo run -- fac --rec 5
./target/release/rust-xp fac --rec 5
# Fibonacci (iterative by default)
cargo run -- fib 7
./target/release/rust-xp fib 7
# Fibonacci (recursive)
cargo run -- fib --rec 10
./target/release/rust-xp fib --rec 10Individual binary executables are also available:
# Factorial
cargo run --bin factorial_itr 5
cargo run --bin factorial_rec 5
# Fibonacci
cargo run --bin fibonacci_itr 7
cargo run --bin fibonacci_rec 10
# Prime check
cargo run --bin is_prime 17rust-xp/
├── src/
│ ├── lib.rs # Core library with all implementations
│ ├── main.rs # Main CLI interface
│ └── bin/ # Individual binary executables
│ ├── factorial_itr.rs
│ ├── factorial_rec.rs
│ ├── fibonacci_itr.rs
│ ├── fibonacci_rec.rs
│ └── is_prime.rs
├── Cargo.toml
├── README.md
├── CONTRIBUTING.md
└── LICENSE
# Run all tests (includes unit tests and doc tests)
cargo test
# Run tests with output
cargo test -- --nocapture
# Run specific test module
cargo test --lib -- testsThis project uses cargo-llvm-cov for code coverage analysis. Install it with:
cargo install cargo-llvm-covGenerate coverage reports:
# Generate coverage report (summary in terminal)
cargo llvm-cov
# Generate HTML coverage report (opens in browser)
cargo llvm-cov --html --open
# Generate detailed text report
cargo llvm-cov --text
# Generate coverage with specific output format
cargo llvm-cov --lcov --output-path target/lcov.info
# Clean coverage data
cargo llvm-cov cleanCoverage reports include:
- Line coverage for all source files
- Function coverage statistics
- Branch coverage analysis
- Detailed HTML reports in
target/llvm-cov/html/
# Run all benchmarks
cargo bench
# Run specific benchmark
cargo bench factorial
# Run benchmarks and save baseline
cargo bench -- --save-baseline my-baseline
# Compare against baseline
cargo bench -- --baseline my-baselineThe benchmarks compare:
- Iterative vs recursive implementations
- Performance across different input sizes
- Prime checking performance
Results are saved in target/criterion/ with detailed HTML reports.
See BENCHMARKING.md for detailed benchmarking guide.
# Build and open documentation
cargo doc --openCalculates n! = n × (n-1) × (n-2) × ... × 2 × 1
- Iterative: Uses a loop, O(n) time and O(1) space
- Recursive: Uses recursion, O(n) time and O(n) space
Calculates the nth Fibonacci number where F(n) = F(n-1) + F(n-2)
- Iterative: Uses a loop, O(n) time and O(1) space
- Recursive: Uses recursion, O(2^n) time and O(n) space
Determines if a number is prime using trial division up to √n.
Please see CONTRIBUTING.md for guidelines on how to contribute to this project.
This project is licensed under the MIT License - see the LICENSE file for details.
This project is designed to:
- Practice Rust syntax and idioms
- Understand iterative vs recursive approaches
- Learn Rust's module system and project structure
- Explore testing in Rust (unit tests and doc tests)
- Work with Rust's error handling
- Implement a CLI application
- Add more algorithms (sorting, searching)
- Implement memoization for recursive Fibonacci
- Add benchmarking
- Improve error handling and input validation
- Add more comprehensive tests