Rust Claude Code Starter Template
A comprehensive starter template for Rust projects optimized for development with Claude Code. This template provides a solid foundation with best practices, tooling configurations, and development guidelines for building robust Rust applications.
π Quick Start
-
Clone this template
git clone https://github.com/iepathos/rust-claude-code.git my-rust-project
cd my-rust-project
-
Initialize your project
# Remove template git history
rm -rf .git
git init
# Create initial Cargo.toml
cargo init --name my-project
-
Install development dependencies
# Install rustfmt and clippy
rustup component add rustfmt clippy
# Install cargo-watch for development
cargo install cargo-watch
# Install additional tools (optional)
cargo install cargo-tarpaulin # Code coverage
cargo install cargo-audit # Security audits
cargo install cargo-outdated # Dependency updates
π Project Structure
my-rust-project/
βββ src/ # Source code
β βββ main.rs # Binary entry point
β βββ lib.rs # Library entry point
β βββ modules/ # Application modules
βββ tests/ # Integration tests
βββ benches/ # Benchmarks
βββ examples/ # Usage examples
βββ docs/ # Documentation
βββ .gitignore # Git ignore rules
βββ CLAUDE.md # Claude Code guidelines
βββ Cargo.toml # Project manifest
βββ README.md # This file
π οΈ Development Workflow
Running the project
# Build and run
cargo run
# Run with hot reloading
cargo watch -x run
# Run tests
cargo test
# Run with all features
cargo run --all-features
Code Quality
# Format code
cargo fmt
# Run linter
cargo clippy -- -D warnings
# Check without building
cargo check
# Run security audit
cargo audit
Testing
# Run all tests
cargo test
# Run tests with output
cargo test -- --nocapture
# Run specific test
cargo test test_name
# Generate code coverage
cargo tarpaulin --out Html
π€ Claude Code Integration
This template includes a comprehensive CLAUDE.md file that provides:
- Architecture guidelines: Error handling, concurrency patterns, and configuration management
- Code style standards: Documentation, logging, and testing requirements
- Development patterns: Best practices and anti-patterns specific to Rust
- Example prompts: How to effectively communicate with Claude for various tasks
Key Features for Claude Development
-
Structured Error Handling
- Uses
Result<T, E> types consistently
- Includes examples with
anyhow and thiserror
-
Async/Await Support
- Pre-configured for
tokio runtime
- Examples for concurrent operations
-
Comprehensive Testing
- Unit test templates
- Property-based testing with
proptest
- Integration test structure
-
Documentation Standards
- Rustdoc comment templates
- Example-driven documentation
π¦ Recommended Dependencies
Add these to your Cargo.toml as needed:
[dependencies]
# Async runtime
tokio = { version = "1", features = ["full"] }
# Error handling
anyhow = "1"
thiserror = "1"
# Serialization
serde = { version = "1", features = ["derive"] }
serde_json = "1"
# Logging
tracing = "0.1"
tracing-subscriber = "0.3"
# CLI
clap = { version = "4", features = ["derive"] }
# HTTP client
reqwest = { version = "0.11", features = ["json"] }
[dev-dependencies]
# Testing
proptest = "1"
mockall = "0.11"
criterion = "0.5"
tempfile = "3"
π§ Configuration
Environment Variables
Create a .env file for local development:
# Application settings
RUST_LOG=debug
DATABASE_URL=postgresql://localhost/myapp
API_KEY=your_api_key_here
VS Code Settings
Recommended .vscode/settings.json:
{
"rust-analyzer.cargo.features": ["all"],
"rust-analyzer.checkOnSave.command": "clippy",
"editor.formatOnSave": true,
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer"
}
}
π Building for Production
# Build release version
cargo build --release
# Run release version
cargo run --release
# Create optimized binary
RUSTFLAGS="-C target-cpu=native" cargo build --release
π Learning Resources
π€ Contributing
When contributing to this template:
- Follow the guidelines in
CLAUDE.md
- Ensure all tests pass:
cargo test
- Run formatters:
cargo fmt
- Check lints:
cargo clippy
- Update documentation as needed
π License
This template is provided as-is for use in your own projects. Customize the license as needed for your specific use case.
π― Next Steps
- Customize
Cargo.toml with your project details
- Update this README with project-specific information
- Review
CLAUDE.md for development guidelines
- Set up CI/CD with GitHub Actions or similar
- Start building your Rust application!
Happy coding with Rust and Claude! π¦π€