1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use std::error::Error;
use std::fmt;
use std::sync::Arc;

pub struct ArcError<T: Error>(Arc<T>);

impl<T: Error> fmt::Display for ArcError<T> {
	#[inline]
	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
		<T as fmt::Display>::fmt(self.0.as_ref(), f)
	}
}

impl<T: Error> fmt::Debug for ArcError<T> {
	#[inline]
	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
		<T as fmt::Debug>::fmt(self.0.as_ref(), f)
	}
}

impl<T: Error> Error for ArcError<T> {}

impl<T: Error> From<T> for ArcError<T> {
	#[inline]
	fn from(inner: T) -> Self {
		Self(Arc::new(inner))
	}
}

impl<T: Error> Clone for ArcError<T> {
	#[inline]
	fn clone(&self) -> Self {
		Self(self.0.clone())
	}
}