Skip to content

Commit e094af6

Browse files
authored
feat: impl StackError for Arc<T: StackError> (#15)
## Description Adds an impl for `StackError` for `Arc<T: StackError + std::error::Error>`. Makes it easy to to cloneable errors.
1 parent 8363fef commit e094af6

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

src/error.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use std::fmt::{self, Formatter};
1+
use std::{
2+
fmt::{self, Formatter},
3+
sync::Arc,
4+
};
25

36
use crate::{AnyError, Location, Meta, backtrace_enabled};
47

@@ -353,3 +356,33 @@ impl_stack_error_for_std_error!(std::str::Utf8Error);
353356
impl_stack_error_for_std_error!(std::string::FromUtf8Error);
354357
impl_stack_error_for_std_error!(std::net::AddrParseError);
355358
impl_stack_error_for_std_error!(std::array::TryFromSliceError);
359+
360+
impl<T: StackError + std::error::Error + Sized + 'static> StackError for Arc<T> {
361+
fn as_std(&self) -> &(dyn std::error::Error + Send + Sync + 'static) {
362+
(**self).as_std()
363+
}
364+
365+
fn into_std(self: Box<Self>) -> Box<dyn std::error::Error + Send + Sync> {
366+
self
367+
}
368+
369+
fn as_dyn(&self) -> &dyn StackError {
370+
(**self).as_dyn()
371+
}
372+
373+
fn meta(&self) -> Option<&Meta> {
374+
(**self).meta()
375+
}
376+
377+
fn source(&self) -> Option<ErrorRef<'_>> {
378+
StackError::source(&**self)
379+
}
380+
381+
fn fmt_message(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
382+
(**self).fmt_message(f)
383+
}
384+
385+
fn is_transparent(&self) -> bool {
386+
(**self).is_transparent()
387+
}
388+
}

0 commit comments

Comments
 (0)