rusmpp_extra/fallback.rs
1//! Fallback behavior for encoding/decoding and concatenation.
2
3/// Fallback error combining two errors.
4#[derive(Debug, thiserror::Error)]
5#[error("Both operations failed: {first}, {second}")]
6pub struct FallbackError<T, U> {
7 pub first: T,
8 pub second: U,
9}
10
11impl<T, U> FallbackError<T, U> {
12 /// Creates a new [`FallbackError`].
13 pub const fn new(first: T, second: U) -> Self {
14 Self { first, second }
15 }
16}
17
18/// A wrapper that tries the first operation, and if it fails, tries the second.
19#[derive(Debug)]
20pub struct Fallback<T, U> {
21 pub first: T,
22 pub second: U,
23}
24
25impl<T, U> Fallback<T, U> {
26 /// Creates a new [`Fallback`].
27 pub const fn new(first: T, second: U) -> Self {
28 Self { first, second }
29 }
30}