pub struct Fallback<F, T> { /* private fields */ }Expand description
A policy that returns a fallback value when the operation fails.
This is useful for graceful degradation - instead of propagating an error, you can return a sensible default value.
§Examples
use do_over::{policy::Policy, fallback::Fallback, error::DoOverError};
// Simple fallback with a static value
let policy = Fallback::new(|| "cached_data".to_string());
// Fallback that computes a value
let policy = Fallback::new(|| {
vec!["item1".to_string(), "item2".to_string()]
});Implementations§
Source§impl<F, T> Fallback<F, T>
impl<F, T> Fallback<F, T>
Sourcepub fn new(fallback_fn: F) -> Self
pub fn new(fallback_fn: F) -> Self
Create a new fallback policy.
§Arguments
fallback_fn- A function that produces the fallback value
§Examples
use do_over::fallback::Fallback;
// Return empty vec on failure
let policy = Fallback::new(|| Vec::<String>::new());
// Return a default struct
let policy = Fallback::new(|| "default".to_string());Trait Implementations§
Auto Trait Implementations§
impl<F, T> Freeze for Fallback<F, T>where
F: Freeze,
impl<F, T> RefUnwindSafe for Fallback<F, T>where
F: RefUnwindSafe,
T: RefUnwindSafe,
impl<F, T> Send for Fallback<F, T>
impl<F, T> Sync for Fallback<F, T>
impl<F, T> Unpin for Fallback<F, T>
impl<F, T> UnwindSafe for Fallback<F, T>where
F: UnwindSafe,
T: 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