A collection of reusable Rust utilities, models, and components designed to accelerate development across future projects. This repository serves as a centralized library of well-tested, production-ready code that can be easily integrated into new Rust applications.
This repository contains a growing collection of Rust utilities that solve common development challenges. Each module is designed with reusability, maintainability, and performance in mind, following Rust best practices and idiomatic patterns.
- API Response Handling: Standardized HTTP response structures with comprehensive status codes
- Service Response Management: Internal service layer response handling with detailed error categorization
- Type-safe error handling with clear status indicators
- Built-in success/error state validation
src/
βββ error-handlers/
β βββ api_response.rs # HTTP API response structures and utilities
β βββ service_response.rs # Service layer response handling
Provides standardized HTTP response handling with:
- Comprehensive HTTP status code enumeration
- Generic
ApiResponse<T>
structure for type-safe responses - Convenient constructor methods for common response types
- Built-in status code mapping
Key Components:
HttpStatus
enum with detailed HTTP status codesApiResponse<T>
struct for consistent API responses- Helper methods for common scenarios (success, error, not found, etc.)
Internal service layer response management featuring:
- Business logic specific status codes
- Detailed error categorization
- Optional error details for debugging
- Clear success/failure indicators
Key Components:
ServiceStatus
enum for business logic statesServiceResponse<T>
struct for service layer operations- Specialized constructors for different error types
- Rust 1.70+ (recommended)
- Cargo package manager
- Clone the repository:
git clone <repository-url>
cd utils_rust
- Add as a dependency in your
Cargo.toml
:
[dependencies]
utils_rust = { path = "../utils_rust" }
Or include specific modules in your project by copying the relevant files.
use utils_rust::error_handlers::api_response::{ApiResponse, HttpStatus};
// Success response with data
let user_data = User { id: 1, name: "John".to_string() };
let response = ApiResponse::success(user_data, "User retrieved successfully".to_string());
// Error response
let error_response = ApiResponse::not_found("User not found".to_string());
// Check response status
if response.is_success() {
println!("Operation successful: {}", response.message);
}
use utils_rust::error_handlers::service_response::{ServiceResponse, ServiceStatus};
// Service operation success
let result = ServiceResponse::success(
processed_data,
"Data processed successfully".to_string()
);
// Service validation error
let validation_error = ServiceResponse::validation_error(
"Email format is invalid".to_string()
);
// Handle different error types
match result.status {
ServiceStatus::Success => println!("Success: {}", result.message),
ServiceStatus::ValidationError => println!("Validation failed: {}", result.message),
_ => println!("Operation failed: {}", result.message),
}
When contributing new utilities to this repository:
- Modularity: Each utility should be self-contained and focused on a specific concern
- Documentation: Include comprehensive documentation with examples
- Testing: Add unit tests for all public functions and edge cases
- Error Handling: Use proper Rust error handling patterns
- Performance: Consider performance implications and optimize where necessary
- Follow Rust standard formatting (
cargo fmt
) - Use meaningful variable and function names
- Include comprehensive documentation comments
- Implement appropriate traits (
Debug
,Clone
, etc.) where beneficial
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-utility
) - Make your changes following the development guidelines
- Add tests for new functionality
- Commit your changes (
git commit -m 'Add amazing utility'
) - Push to the branch (
git push origin feature/amazing-utility
) - Open a Pull Request
- Database connection pooling utilities
- Logging and tracing utilities
- Authentication and authorization helpers
- Caching utilities
- File handling utilities
- Validation helpers
- Serialization utilities
This project is licensed under the MIT License - see the LICENSE file for details.
Note: This is a living repository that will grow over time. Each utility is designed to be production-ready and thoroughly tested before inclusion.