pub trait SourceErr<T, R: DomainReason>: Sized {
// Required method
fn source_err(
self,
reason: R,
detail: impl Into<String>,
) -> Result<T, StructError<R>>;
}Expand description
Convert a Result<T, E> into Result<T, StructError<R>>, attaching the
original error as the source of the new structured error.
Works for both raw std::error::Error types and already-structured
StructError sources.
§Example
use orion_error::prelude::*;
use orion_error::UnifiedReason;
let result: Result<(), std::io::Error> = Err(std::io::Error::other("disk offline"));
let err: Result<(), StructError<UnifiedReason>> =
result.source_err(UnifiedReason::system_error(), "read config");
assert!(err.unwrap_err().detail().as_deref() == Some("read config"));§Note on trait resolution
There are two blanket impls: one for raw StdError sources (via
UnstructuredSource), and one for already-structured StructError
sources. These do not conflict because StructError<R> does not
implement UnstructuredSource.
Required Methods§
fn source_err( self, reason: R, detail: impl Into<String>, ) -> Result<T, StructError<R>>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.