Skip to main content

raw_source

Function raw_source 

Source
pub fn raw_source<E>(err: E) -> RawSource<E>
where E: RawStdError,
Expand description

Explicitly mark an opt-in raw std::error::Error as an unstructured source.

This is a narrow explicit escape hatch. It does not provide a blanket E: StdError path, and it must not be used for StructError<_>.

Downstream crates may opt in their own raw StdError types by implementing RawStdError, instead of relying on a blanket E: StdError fallback.

use std::fmt;

use orion_error::prelude::*;
use orion_error::UnifiedReason;
use orion_error::interop::{raw_source, RawStdError};

#[derive(Debug)]
struct ThirdPartyError;

impl fmt::Display for ThirdPartyError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "third-party failure")
    }
}

impl std::error::Error for ThirdPartyError {}
impl RawStdError for ThirdPartyError {}

let result: Result<(), ThirdPartyError> = Err(ThirdPartyError);
let err = result
    .map_err(raw_source)
    .source_err(UnifiedReason::system_error(), "load failed")
    .expect_err("expected structured error");

assert_eq!(err.source_ref().unwrap().to_string(), "third-party failure");
use orion_error::{StructError, UnifiedReason};
use orion_error::interop::{raw_source, RawStdError};

let structured = StructError::from(UnifiedReason::system_error());
let _ = raw_source(structured);