Expand description
Policy composition using the Wrap combinator.
The Wrap struct allows you to compose multiple policies together,
creating sophisticated resilience strategies.
§Execution Order
Execution flows from outer → inner → operation. The outer policy wraps the inner policy, which wraps your operation.
§Recommended Policy Ordering
From outer to inner:
- Bulkhead - Limit concurrency first
- Circuit Breaker - Fast-fail if too many errors
- Rate Limiter - Throttle requests
- Retry - Handle transient failures
- Timeout - Bound individual attempts
§Examples
use do_over::{policy::Policy, wrap::Wrap, retry::RetryPolicy, timeout::TimeoutPolicy, error::DoOverError};
use std::time::Duration;
// Simple composition: retry with timeout
let policy = Wrap::new(
RetryPolicy::fixed(3, Duration::from_millis(100)),
TimeoutPolicy::new(Duration::from_secs(5)),
);
let result: Result<&str, DoOverError<&str>> = policy.execute(|| async {
Ok("success")
}).await;Structs§
- Wrap
- Composes two policies together.