TryReportTupleExt

Trait TryReportTupleExt 

Source
pub trait TryReportTupleExt<C> {
    type Output;

    // Required method
    fn try_collect(self) -> Result<Self::Output, Report<[C]>>;
}
Available on crate feature unstable only.
Expand description

Extends tuples with error-handling capabilities.

This trait provides a method to collect a tuple of Results into a single Result containing a tuple of the successful values, or an error if any of the results failed.

The trait is implemented for tuples of up to 16 elements.

§Stability

This trait is only available behind the unstable feature flag and is not covered by semver guarantees. It may change or be removed in future versions without notice.

Required Associated Types§

Source

type Output

The type of the successful output, typically a tuple of the inner types of the Results.

Required Methods§

Source

fn try_collect(self) -> Result<Self::Output, Report<[C]>>

Attempts to collect all Results in the tuple into a single Result.

§Errors

If any element is Err, returns the first encountered Err, with subsequent errors appended to it.

§Examples
use error_stack::{Report, TryReportTupleExt};

#[derive(Debug)]
struct CustomError;

impl core::fmt::Display for CustomError {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "Custom error")
    }
}

impl core::error::Error for CustomError {}

let result1: Result<i32, Report<CustomError>> = Ok(1);
let result2: Result<&'static str, Report<CustomError>> = Ok("success");
let result3: Result<bool, Report<CustomError>> = Ok(true);

let combined = (result1, result2, result3).try_collect();
assert_eq!(combined.unwrap(), (1, "success", true));

let result1: Result<i32, Report<CustomError>> = Ok(1);
let result2: Result<&'static str, Report<CustomError>> = Err(Report::new(CustomError));
let result3: Result<bool, Report<CustomError>> = Err(Report::new(CustomError));
let combined_with_error = (result1, result2, result3).try_collect();
assert!(combined_with_error.is_err());

Implementations on Foreign Types§

Source§

impl<A, AO, B, BO, C, CO, D, DO, E, EO, F, FO, G, GO, H, HO, I, IO, J, JO, K, KO, L, LO, M, MO, N, NO, O, OO, P, PO, T, R, Context> TryReportTupleExt<Context> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Result<T, R>)

Source§

impl<A, AO, B, BO, C, CO, D, DO, E, EO, F, FO, G, GO, H, HO, I, IO, J, JO, K, KO, L, LO, M, MO, N, NO, O, OO, T, R, Context> TryReportTupleExt<Context> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, Result<T, R>)

Source§

impl<A, AO, B, BO, C, CO, D, DO, E, EO, F, FO, G, GO, H, HO, I, IO, J, JO, K, KO, L, LO, M, MO, N, NO, T, R, Context> TryReportTupleExt<Context> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, Result<T, R>)

Source§

impl<A, AO, B, BO, C, CO, D, DO, E, EO, F, FO, G, GO, H, HO, I, IO, J, JO, K, KO, L, LO, M, MO, T, R, Context> TryReportTupleExt<Context> for (A, B, C, D, E, F, G, H, I, J, K, L, M, Result<T, R>)

Source§

impl<A, AO, B, BO, C, CO, D, DO, E, EO, F, FO, G, GO, H, HO, I, IO, J, JO, K, KO, L, LO, T, R, Context> TryReportTupleExt<Context> for (A, B, C, D, E, F, G, H, I, J, K, L, Result<T, R>)

Source§

impl<A, AO, B, BO, C, CO, D, DO, E, EO, F, FO, G, GO, H, HO, I, IO, J, JO, K, KO, T, R, Context> TryReportTupleExt<Context> for (A, B, C, D, E, F, G, H, I, J, K, Result<T, R>)

Source§

impl<A, AO, B, BO, C, CO, D, DO, E, EO, F, FO, G, GO, H, HO, I, IO, J, JO, T, R, Context> TryReportTupleExt<Context> for (A, B, C, D, E, F, G, H, I, J, Result<T, R>)

Source§

impl<A, AO, B, BO, C, CO, D, DO, E, EO, F, FO, G, GO, H, HO, I, IO, T, R, Context> TryReportTupleExt<Context> for (A, B, C, D, E, F, G, H, I, Result<T, R>)

Source§

impl<A, AO, B, BO, C, CO, D, DO, E, EO, F, FO, G, GO, H, HO, T, R, Context> TryReportTupleExt<Context> for (A, B, C, D, E, F, G, H, Result<T, R>)

Source§

impl<A, AO, B, BO, C, CO, D, DO, E, EO, F, FO, G, GO, T, R, Context> TryReportTupleExt<Context> for (A, B, C, D, E, F, G, Result<T, R>)

Source§

impl<A, AO, B, BO, C, CO, D, DO, E, EO, F, FO, T, R, Context> TryReportTupleExt<Context> for (A, B, C, D, E, F, Result<T, R>)

Source§

impl<A, AO, B, BO, C, CO, D, DO, E, EO, T, R, Context> TryReportTupleExt<Context> for (A, B, C, D, E, Result<T, R>)

Source§

impl<A, AO, B, BO, C, CO, D, DO, T, R, Context> TryReportTupleExt<Context> for (A, B, C, D, Result<T, R>)

Source§

impl<A, AO, B, BO, C, CO, T, R, Context> TryReportTupleExt<Context> for (A, B, C, Result<T, R>)
where R: Into<Report<[Context]>>, (A, B, C): TryReportTupleExt<Context, Output = (AO, BO, CO)>,

Source§

impl<A, AO, B, BO, T, R, Context> TryReportTupleExt<Context> for (A, B, Result<T, R>)
where R: Into<Report<[Context]>>, (A, B): TryReportTupleExt<Context, Output = (AO, BO)>,

Source§

impl<A, AO, T, R, Context> TryReportTupleExt<Context> for (A, Result<T, R>)
where R: Into<Report<[Context]>>, (A,): TryReportTupleExt<Context, Output = (AO,)>,

Source§

impl<T, R, C> TryReportTupleExt<C> for (Result<T, R>,)
where R: Into<Report<[C]>>,

Implementors§