A modern Rust boilerplate template with async runtime, environment management, and containerization support.
- Rust 2024 Edition with stable toolchain
- Async Runtime powered by Tokio
- Environment Configuration with dotenvy
- Reproducible Development using devenv (Nix)
- Docker Ready with optimized multi-stage builds
- Development Tools pre-configured (clippy, rustfmt, rust-analyzer)
# Clone and setup
git clone https://github.com/tencat-dev/rust-base.git my-project
cd my-project
cp .env.example .env
# Run with devenv (recommended)
devenv shell
cargo run
# Or run with cargo directly
cargo run
# Or use Docker
docker build -t my-project .
docker run --env-file .env my-project
# Install Nix and devenv
curl -L https://install.determinate.systems/nix | sh
nix profile install nixpkgs#devenv
# Enter development environment
devenv shell
# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup component add clippy rustfmt rust-analyzer
rust-base/
βββ src/main.rs # Application entry point
βββ .env.example # Environment template
βββ Cargo.toml # Package manifest
βββ devenv.nix # Development environment
βββ Dockerfile # Container configuration
βββ README.md # This file
Create .env
from template and configure as needed:
# .env
HOST=localhost
PORT=8080
RUST_LOG=info
# Development mode
cargo run
# With file watching
cargo watch -x run
# Release mode
cargo build --release
./target/release/rust-base
# Format code
cargo fmt
# Lint code
cargo clippy
# Run tests
cargo test
# Generate documentation
cargo doc --open
# Build image
docker build -t rust-base .
# Run container
docker run --env-file .env rust-base
# Development with volume
docker run -v $(pwd):/app --env-file .env rust-base
# Run all tests
cargo test
# Run with output
cargo test -- --nocapture
# Integration tests
cargo test --test integration
Required environment variables:
HOST
: Server hostnamePORT
: Server port (optional, defaults in code)RUST_LOG
: Logging level (optional)
- Fork the repository
- Create a feature branch:
git checkout -b feature/new-feature
- Make changes and test:
cargo test && cargo clippy
- Format code:
cargo fmt
- Commit changes:
git commit -m 'Add new feature'
- Push and create a Pull Request
Environment variables not loading:
# Ensure .env exists
cp .env.example .env
Build failures:
# Update Rust
rustup update
# Clear cache
cargo clean
Docker issues:
# Rebuild without cache
docker build --no-cache -t rust-base .
This project is licensed under the MIT License - see the LICENSE file for details.
Built with β€οΈ using Rust