Skip to main content

Module wrap

Module wrap 

Source
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.

From outer to inner:

  1. Bulkhead - Limit concurrency first
  2. Circuit Breaker - Fast-fail if too many errors
  3. Rate Limiter - Throttle requests
  4. Retry - Handle transient failures
  5. 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.