| Crates.io | decrust_promac |
| lib.rs | decrust_promac |
| version | 1.2.6 |
| created_at | 2025-05-25 19:17:24.349428+00 |
| updated_at | 2025-05-25 19:31:15.396397+00 |
| description | Procedural macros for the Decrust Error handling framework |
| homepage | |
| repository | https://github.com/arcmoonstudios/decrust |
| max_upload_size | |
| id | 1688616 |
| size | 234,188 |
Procedural Macros for the Decrust Error Handling Framework
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.
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(())
}
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?
};
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);
Automatic location and context tracking:
use decrust::*;
// Automatic location tracking in generated code
let location = location!(
context: "user authentication",
function: "validate_credentials"
);
The decrust! macro automatically handles:
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);
}
}
}
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")?;
}
The procedural macros in this crate:
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
}
// Enable macro debugging (development only)
#[cfg(debug_assertions)]
decrust! {
debug: true,
trace_expansions: true,
let result = operation_to_debug()?;
result
}
This project is licensed under the Business Source License 1.1 (BSL 1.1).
Change Date: 2029-05-25 | Change License: GNU GPL v3
Made with ❤️ by ArcMoon Studios