arb_storage_errors/
any.rs1use alloc::sync::Arc;
2use core::{error::Error, fmt};
3
4#[derive(Clone)]
10pub struct AnyError {
11 inner: Arc<dyn Error + Send + Sync + 'static>,
12}
13
14impl AnyError {
15 pub fn new<E>(error: E) -> Self
17 where
18 E: Error + Send + Sync + 'static,
19 {
20 Self {
21 inner: Arc::new(error),
22 }
23 }
24
25 pub fn as_error(&self) -> &(dyn Error + Send + Sync + 'static) {
27 self.inner.as_ref()
28 }
29}
30
31impl fmt::Debug for AnyError {
32 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33 fmt::Debug::fmt(&self.inner, f)
34 }
35}
36
37impl fmt::Display for AnyError {
38 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39 fmt::Display::fmt(&self.inner, f)
40 }
41}
42
43impl Error for AnyError {
44 fn source(&self) -> Option<&(dyn Error + 'static)> {
45 self.inner.source()
46 }
47}