Thank you for your interest in contributing to rust-xp! This document provides guidelines and instructions for contributing to this project.
- Be respectful and inclusive
- Focus on constructive feedback
- Help others learn and grow
- Fork the repository
- Clone your fork:
git clone <your-fork-url> - Create a new branch:
git checkout -b feature/your-feature-name - Make your changes
- Test your changes:
cargo test - Commit your changes (see commit guidelines below)
- Push to your fork:
git push origin feature/your-feature-name - Open a Pull Request
- Rust (latest stable version)
- Cargo (comes with Rust)
# Debug build
cargo build
# Release build
cargo build --release# Run all tests
cargo test
# Run tests with output
cargo test -- --nocapture
# Run specific test
cargo test test_factorial_iterative# Install llvm-cov if not already installed
cargo install cargo-llvm-cov
# Generate coverage report
cargo llvm-cov
# Generate HTML coverage report
cargo 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-baseline
# View HTML reports
open target/criterion/report/index.htmlWhen adding new features, consider adding benchmarks to measure performance, especially when:
- Implementing multiple approaches to the same problem
- Optimizing existing code
- Comparing iterative vs recursive solutions
We follow the Conventional Commits specification.
<type>(<scope>): <subject>
[optional body]
[optional footer]
feat: New featuresfix: Bug fixesdocs: Documentation changestest: Test additions/modificationsrefactor: Code refactoring (no functional changes)perf: Performance improvementsci: CI/CD changesbuild: Build system changesstyle: Code style changes (formatting, etc.)
factorial: Factorial implementationsfibonacci: Fibonacci implementationsprime: Prime number functionalitylib: Library functions insrc/lib.rscli: Main CLI interface insrc/main.rsbin: Individual binary filestests: Test codebench: Benchmarking codeci: CI configurationdocs: Documentation
feat(fibonacci): add iterative implementation
fix(factorial): handle overflow for large inputs
refactor(lib): move math functions to library
feat(cli): add unified command-line interface
test(fibonacci): add edge case tests
docs(readme): update usage examples
perf(fibonacci): optimize iterative calculation
feat(bench): add criterion benchmarks for all algorithms
- Keep commits atomic: One logical change per commit
- Use present tense, imperative mood: "add" not "added" or "adds"
- Keep subject line under 50 characters
- Capitalize the subject line
- Don't end subject line with a period
- Wrap body at 72 characters (if adding a body)
- Use the body to explain what and why, not how
- Follow the Rust Style Guide
- Use
rustfmtfor formatting:cargo fmt - Use
clippyfor linting:cargo clippy
- Function naming: Use descriptive names with underscores (
factorial_iterative) - Documentation: Add doc comments (
///) for all public functions - Examples: Include examples in doc comments (they run as doc tests!)
- Error handling: Use
Resultand?operator where appropriate - Keep binaries minimal: Put logic in the library (
src/lib.rs) - Import organization: Group imports (std, external crates, local)
/// Calculates the factorial of a number iteratively.
///
/// # Arguments
///
/// * `n` - The number to calculate the factorial of
///
/// # Returns
///
/// The factorial of `n` as a `u128`
///
/// # Examples
///
/// ```
/// use rust_xp::factorial_iterative;
/// assert_eq!(factorial_iterative(5), 120);
/// ```
pub fn factorial_iterative(n: u32) -> u128 {
// implementation
}src/lib.rs: Core library with all math functions and utilitiessrc/main.rs: Main CLI interface (default binary)src/bin/: Individual binary executables (legacy, kept for compatibility)
-
Add the implementation to
src/lib.rs- Write the function with documentation
- Include doc test examples
- Add unit tests in the
#[cfg(test)]module
-
Add CLI support to
src/main.rs(if applicable)- Add command handling
- Update help text
-
Optional: Create a standalone binary in
src/bin/- Keep it minimal
- Import and use library functions
-
Update documentation
- Update
README.mdwith usage examples - Update this file if contributing guidelines change
- Update
All tests are centralized in src/lib.rs for easier maintenance.
- Unit tests: Test individual functions
- Doc tests: Test code examples in documentation
- Integration tests: Test CLI behavior (if needed)
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_factorial_zero() {
assert_eq!(factorial_iterative(0), 1);
}
#[test]
fn test_factorial_positive() {
assert_eq!(factorial_iterative(5), 120);
}
}- Test edge cases (0, 1, maximum values)
- Test typical cases
- Test error conditions
- Aim for high code coverage (use
cargo llvm-cov)
- Ensure all tests pass:
cargo test - Format your code:
cargo fmt - Run clippy:
cargo clippy - Update documentation if needed
- Write a clear PR description:
- What changes were made
- Why the changes were necessary
- Any breaking changes
- Related issues (if any)
- Wait for review
- Address feedback if requested
- Open an issue for bugs or feature requests
- Use discussions for questions
- Check existing issues before creating new ones
Thank you for contributing! 🦀