Skip to main content

Module fallback

Module fallback 

Source
Expand description

Fallback policy for providing default values on failure.

The fallback policy catches errors and returns a default value instead, allowing operations to gracefully degrade rather than fail.

§Examples

use do_over::{policy::Policy, fallback::Fallback, error::DoOverError};

// Return a default value when the operation fails
let policy = Fallback::new(|| "default value".to_string());

let result: Result<String, DoOverError<String>> = policy.execute(|| async {
    Err(DoOverError::Inner("error".to_string()))
}).await;

assert_eq!(result.unwrap(), "default value");

Structs§

Fallback
A policy that returns a fallback value when the operation fails.
FallbackValue
A fallback policy that works with any result type by converting the fallback.

Traits§

FallbackExt
Extension trait for adding fallback behavior to Results.