pub struct WithFallback<P, F> { /* private fields */ }Expand description
Tries the primary strategy first, falls back to secondary if primary returns None.
This is a generic combinator — zero-cost at runtime because both strategies are
monomorphised. Use FallbackChain when you need a dynamic list of strategies.
§When does fallback trigger?
A strategy returns None when candidates is empty or all candidates are
excluded via SelectionContext::exclude. WithFallback is most useful when
composed with filtered candidate lists or retry-with-exclude patterns.
§Examples
use loadwise::{Strategy, SelectionContext};
use loadwise::strategy::{Random, RoundRobin, WithFallback};
// Prefer random, but fall back to round-robin if it returns None.
let strategy = WithFallback::new(Random::new(), RoundRobin::new());
let nodes = [1, 2, 3];
let ctx = SelectionContext::default();
assert!(strategy.select(&nodes, &ctx).is_some());Implementations§
Source§impl<P, F> WithFallback<P, F>
impl<P, F> WithFallback<P, F>
Trait Implementations§
Source§impl<N, P, F> Strategy<N> for WithFallback<P, F>
impl<N, P, F> Strategy<N> for WithFallback<P, F>
Source§fn select(&self, candidates: &[N], ctx: &SelectionContext) -> Option<usize>
fn select(&self, candidates: &[N], ctx: &SelectionContext) -> Option<usize>
Pick the next node. Returns
None when candidates is empty or all
candidates are excluded via SelectionContext::exclude.Auto Trait Implementations§
impl<P, F> Freeze for WithFallback<P, F>
impl<P, F> RefUnwindSafe for WithFallback<P, F>where
P: RefUnwindSafe,
F: RefUnwindSafe,
impl<P, F> Send for WithFallback<P, F>
impl<P, F> Sync for WithFallback<P, F>
impl<P, F> Unpin for WithFallback<P, F>
impl<P, F> UnsafeUnpin for WithFallback<P, F>where
P: UnsafeUnpin,
F: UnsafeUnpin,
impl<P, F> UnwindSafe for WithFallback<P, F>where
P: UnwindSafe,
F: 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