pub struct FallbackLayer<A, B> {
pub primary: A,
pub secondary: B,
}Expand description
Fallback composition layer that tries primary, falling back to secondary on error.
Created by the | operator on Policy<L> types:
Policy(A) | Policy(B) produces Policy<FallbackLayer<A, B>>.
When a request fails through the primary stack, the original request is retried through the secondary stack. This enables graceful degradation and multi-tier resilience strategies.
§Example
use ninelives::prelude::*;
use std::time::Duration;
use tower_layer::Layer;
// Try fast timeout first, fall back to longer timeout on failure
let fast = Policy(TimeoutLayer::new(Duration::from_millis(100))?);
let slow = Policy(TimeoutLayer::new(Duration::from_secs(5))?);
let _fallback = fast | slow;§Complex Example
use ninelives::prelude::*;
use std::time::Duration;
use tower_layer::Layer;
// Try aggressive strategy, fallback to defensive strategy
let aggressive = Policy(TimeoutLayer::new(Duration::from_millis(50))?);
let defensive = Policy(TimeoutLayer::new(Duration::from_secs(10))?)
+ Policy(TimeoutLayer::new(Duration::from_secs(5))?);
let _policy = aggressive | defensive;
// First tries 50ms timeout, on failure tries nested 10s+5s timeoutsFields§
§primary: AThe primary layer strategy (tried first)
secondary: BThe secondary layer strategy (fallback on primary failure)
Trait Implementations§
Source§impl<S, A, B> Layer<S> for FallbackLayer<A, B>
impl<S, A, B> Layer<S> for FallbackLayer<A, B>
Auto Trait Implementations§
impl<A, B> Freeze for FallbackLayer<A, B>
impl<A, B> RefUnwindSafe for FallbackLayer<A, B>where
A: RefUnwindSafe,
B: RefUnwindSafe,
impl<A, B> Send for FallbackLayer<A, B>
impl<A, B> Sync for FallbackLayer<A, B>
impl<A, B> Unpin for FallbackLayer<A, B>
impl<A, B> UnsafeUnpin for FallbackLayer<A, B>where
A: UnsafeUnpin,
B: UnsafeUnpin,
impl<A, B> UnwindSafe for FallbackLayer<A, B>where
A: UnwindSafe,
B: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more