Skip to content

Collection of reusable Rust utilities, models and components designed to accelerate development across the future projects.

License

Notifications You must be signed in to change notification settings

d4nld3v/utils_rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Rust Utils

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.

πŸ“‹ Table of Contents

🎯 Overview

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.

✨ Features

Error Handlers

  • 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

πŸ“ Project Structure

src/
β”œβ”€β”€ error-handlers/
β”‚   β”œβ”€β”€ api_response.rs      # HTTP API response structures and utilities
β”‚   └── service_response.rs  # Service layer response handling

Error Handlers Module

API Response (api_response.rs)

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 codes
  • ApiResponse<T> struct for consistent API responses
  • Helper methods for common scenarios (success, error, not found, etc.)

Service Response (service_response.rs)

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 states
  • ServiceResponse<T> struct for service layer operations
  • Specialized constructors for different error types

πŸš€ Getting Started

Prerequisites

  • Rust 1.70+ (recommended)
  • Cargo package manager

Installation

  1. Clone the repository:
git clone <repository-url>
cd utils_rust
  1. 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.

πŸ’‘ Usage Examples

API Response Example

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);
}

Service Response Example

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),
}

πŸ”§ Development Guidelines

Adding New Utilities

When contributing new utilities to this repository:

  1. Modularity: Each utility should be self-contained and focused on a specific concern
  2. Documentation: Include comprehensive documentation with examples
  3. Testing: Add unit tests for all public functions and edge cases
  4. Error Handling: Use proper Rust error handling patterns
  5. Performance: Consider performance implications and optimize where necessary

Code Style

  • Follow Rust standard formatting (cargo fmt)
  • Use meaningful variable and function names
  • Include comprehensive documentation comments
  • Implement appropriate traits (Debug, Clone, etc.) where beneficial

🀝 Contributing

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.

Contribution Process

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-utility)
  3. Make your changes following the development guidelines
  4. Add tests for new functionality
  5. Commit your changes (git commit -m 'Add amazing utility')
  6. Push to the branch (git push origin feature/amazing-utility)
  7. Open a Pull Request

πŸ“‹ Roadmap

Planned Utilities

  • Database connection pooling utilities
  • Logging and tracing utilities
  • Authentication and authorization helpers
  • Caching utilities
  • File handling utilities
  • Validation helpers
  • Serialization utilities

πŸ“„ License

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

πŸ”— Related Resources


Note: This is a living repository that will grow over time. Each utility is designed to be production-ready and thoroughly tested before inclusion.

About

Collection of reusable Rust utilities, models and components designed to accelerate development across the future projects.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages