Skip to content

tencat-dev/rust-base

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ¦€ rust-base

Rust License: MIT Docker

A modern Rust boilerplate template with async runtime, environment management, and containerization support.

✨ Features

  • 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)

πŸš€ Quick Start

# 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

πŸ“¦ Installation

Option 1: devenv (Recommended)

# Install Nix and devenv
curl -L https://install.determinate.systems/nix | sh
nix profile install nixpkgs#devenv

# Enter development environment
devenv shell

Option 2: Local Rust

# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup component add clippy rustfmt rust-analyzer

πŸ—οΈ Project Structure

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

βš™οΈ Configuration

Create .env from template and configure as needed:

# .env
HOST=localhost
PORT=8080
RUST_LOG=info

πŸ”¨ Development

Running the Application

# Development mode
cargo run

# With file watching
cargo watch -x run

# Release mode
cargo build --release
./target/release/rust-base

Code Quality

# Format code
cargo fmt

# Lint code
cargo clippy

# Run tests
cargo test

# Generate documentation
cargo doc --open

Docker Usage

# 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

πŸ§ͺ Testing

# Run all tests
cargo test

# Run with output
cargo test -- --nocapture

# Integration tests
cargo test --test integration

Environment Variables

Required environment variables:

  • HOST: Server hostname
  • PORT: Server port (optional, defaults in code)
  • RUST_LOG: Logging level (optional)

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/new-feature
  3. Make changes and test: cargo test && cargo clippy
  4. Format code: cargo fmt
  5. Commit changes: git commit -m 'Add new feature'
  6. Push and create a Pull Request

πŸ”§ Troubleshooting

Common Issues

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 .

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


Built with ❀️ using Rust

About

πŸ¦€ Rust Base Template

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Contributors 2

  •  
  •