decrust_promac

Crates.iodecrust_promac
lib.rsdecrust_promac
version1.2.6
created_at2025-05-25 19:17:24.349428+00
updated_at2025-05-25 19:31:15.396397+00
descriptionProcedural macros for the Decrust Error handling framework
homepage
repositoryhttps://github.com/arcmoonstudios/decrust
max_upload_size
id1688616
size234,188
Lord Xyn (arcmoonstudios)

documentation

README

Decrust_Promac 🦀🔮

Procedural Macros for the Decrust Error Handling Framework

Crates.io Documentation License: BSL-1.1

Decrust_Promac provides the powerful procedural macros that enable the Decrust framework's revolutionary 96% automation rate. This crate contains the decrust! macro and other code generation tools that transform your error handling code.

🚀 Quick Start

This crate is typically used through the main decrust crate:

use decrust::*;  // Includes decrust_promac macros

fn main() -> Result<()> {
    // The decrust! macro automatically handles errors with 96% automation
    let result = decrust! {
        let data = std::fs::read_to_string("config.toml")?;
        let parsed: Config = toml::from_str(&data)?;
        process_config(parsed)
    };
    
    Ok(())
}

🎯 Core Macros

1. decrust! - The Ultimate Error Handler

The main macro that provides 96% automation rate with intelligent error handling:

use decrust::*;

// Automatic error handling with circuit breaker protection
let result = decrust! {
    // File operations - automatically handled
    let config = std::fs::read_to_string("app.toml")?;
    
    // Parsing operations - with validation and recovery
    let settings: AppSettings = toml::from_str(&config)?;
    
    // Network operations - with retry and circuit breaker
    let response = reqwest::get(&settings.api_url).await?;
    
    // All errors are automatically categorized, handled, and recovered
    response.text().await?
};

2. Error Context Macros 📍

Macros for creating rich error context:

use decrust::*;

// Rich error context with automatic location tracking
let error = error_context!(
    "Database operation failed",
    severity: ErrorSeverity::Critical
);

// Validation errors with suggestions
let validation_err = validation_error!(
    "email",
    "Invalid email format",
    suggestion: "Use format: user@domain.com"
);

// Quick error creation with source
let io_error = oops!("File operation failed", source_error);

3. Location Tracking 🗺️

Automatic location and context tracking:

use decrust::*;

// Automatic location tracking in generated code
let location = location!(
    context: "user authentication",
    function: "validate_credentials"
);

🔧 Macro Features

96% Automation Rate 🤖

The decrust! macro automatically handles:

  • ✅ File I/O errors - with automatic retry and fallback
  • ✅ Network errors - with circuit breaker and exponential backoff
  • ✅ Parsing errors - with validation and recovery suggestions
  • ✅ Type conversion errors - with smart casting and validation
  • ✅ Missing imports (E0433) - automatic dependency resolution
  • ✅ Division by zero - automatic safety checks
  • ✅ Borrow checker errors - heuristic recovery patterns
  • ✅ Async/await errors - seamless async error propagation

AST-Driven Code Generation 🌳

Advanced syntax tree analysis for intelligent code transformation:

// Before macro expansion
decrust! {
    let result = risky_operation()?;
    process(result)
}

// After macro expansion (simplified)
{
    let __decrust_circuit_breaker = CircuitBreaker::new("risky_operation", Default::default());
    let __decrust_result = __decrust_circuit_breaker.execute(|| {
        risky_operation().map_err(|e| {
            DecrustError::from(e)
                .with_context("risky_operation")
                .with_location(file!(), line!(), column!())
                .with_recovery_suggestion("Check input parameters")
        })
    });
    
    match __decrust_result {
        Ok(result) => process(result),
        Err(e) => {
            // Automatic error recovery and reporting
            return Err(e);
        }
    }
}

Circuit Breaker Integration

Automatic circuit breaker pattern application:

use decrust::*;

// Circuit breakers are automatically applied to external operations
decrust! {
    // This automatically gets circuit breaker protection
    let api_response = external_api_call().await?;
    
    // Database operations get their own circuit breaker
    let db_result = database_query(&sql).await?;
    
    // File operations get retry logic
    let file_content = std::fs::read_to_string("data.txt")?;
}

🏗️ Architecture

The procedural macros in this crate:

  1. Parse the input syntax tree
  2. Analyze error-prone operations
  3. Generate enhanced error handling code
  4. Inject circuit breaker and retry logic
  5. Add rich error context and location tracking
  6. Optimize for performance and reliability

📚 Advanced Usage

Custom Error Handling

use decrust::*;

// Custom error handling with macro support
decrust! {
    custom_error_handler: |error| {
        log::error!("Custom handling: {}", error);
        // Custom recovery logic
    },
    
    circuit_breaker_config: CircuitBreakerConfig {
        failure_threshold: 3,
        reset_timeout: Duration::from_secs(10),
        ..Default::default()
    },
    
    // Your code here
    let result = complex_operation()?;
    result
}

Macro Debugging

// Enable macro debugging (development only)
#[cfg(debug_assertions)]
decrust! {
    debug: true,
    trace_expansions: true,
    
    let result = operation_to_debug()?;
    result
}

🎨 Code Generation Features

  • Smart Error Categorization - Automatic error type detection
  • Context Injection - Rich error context with minimal overhead
  • Performance Optimization - Zero-cost abstractions where possible
  • Async Support - Seamless async/await integration
  • Custom Recovery - Pluggable recovery strategies
  • Debugging Support - Enhanced debugging information in development

🛡️ Licensing

This project is licensed under the Business Source License 1.1 (BSL 1.1).

  • ✅ Non-production use is FREE (development, testing, academic, personal)
  • 💰 Commercial/production use requires a paid license from ArcMoon Studios
  • 📧 Contact: LordXyn@proton.me for commercial licensing inquiries

Change Date: 2029-05-25 | Change License: GNU GPL v3


Made with ❤️ by ArcMoon Studios

Commit count: 69

cargo fmt