Skip to main content

SourceErr

Trait SourceErr 

Source
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§

Source

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.

Implementations on Foreign Types§

Source§

impl<T, E, R> SourceErr<T, R> for Result<T, E>
where E: UnstructuredSource, R: DomainReason,

Source§

fn source_err( self, reason: R, detail: impl Into<String>, ) -> Result<T, StructError<R>>

Source§

impl<T, R1, R2> SourceErr<T, R2> for Result<T, StructError<R1>>
where R1: DomainReason, R2: DomainReason,

Source§

fn source_err( self, reason: R2, detail: impl Into<String>, ) -> Result<T, StructError<R2>>

Implementors§