futures_concurrency/future/race_ok/array/
error.rs1use core::fmt;
2use core::ops::{Deref, DerefMut};
3#[cfg(feature = "std")]
4use std::error::Error;
5
6#[repr(transparent)]
8pub struct AggregateError<E, const N: usize> {
9 inner: [E; N],
10}
11
12impl<E, const N: usize> AggregateError<E, N> {
13 pub(super) fn new(inner: [E; N]) -> Self {
14 Self { inner }
15 }
16}
17
18impl<E: fmt::Display, const N: usize> fmt::Debug for AggregateError<E, N> {
19 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20 writeln!(f, "{self}:")?;
21
22 for (i, err) in self.inner.iter().enumerate() {
23 writeln!(f, "- Error {}: {err}", i + 1)?;
24 }
25
26 Ok(())
27 }
28}
29
30impl<E: fmt::Display, const N: usize> fmt::Display for AggregateError<E, N> {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 write!(f, "{} errors occured", self.inner.len())
33 }
34}
35
36impl<E, const N: usize> Deref for AggregateError<E, N> {
37 type Target = [E; N];
38
39 fn deref(&self) -> &Self::Target {
40 &self.inner
41 }
42}
43
44impl<E, const N: usize> DerefMut for AggregateError<E, N> {
45 fn deref_mut(&mut self) -> &mut Self::Target {
46 &mut self.inner
47 }
48}
49
50#[cfg(feature = "std")]
51impl<E: Error, const N: usize> std::error::Error for AggregateError<E, N> {}