shepmaster / snafu

Easily assign underlying errors into domain-specific errors while adding context
https://docs.rs/snafu/
Apache License 2.0
1.39k stars 60 forks source link

Restore support for yeeting context selectors #431

Open shepmaster opened 8 months ago

shepmaster commented 8 months ago

Originally added in #395, we discovered it caused some type inference issues. In order to release 0.8 with new features, I'm reverting that code for now.

shepmaster commented 8 months ago

A repro of the issue at hand:

use snafu::prelude::*;

fn make() -> Option<()> {
    None
}

#[derive(Debug, Snafu)]
pub enum ReproError {
    #[snafu(whatever, display("{}", message))]
    Custom {
        message: String,
        #[snafu(source(from(Box<dyn std::error::Error + Send + Sync + 'static>, Some)))]
        source: Option<Box<dyn std::error::Error + Send + Sync + 'static>>,
    },

    NotNative,
}

fn repro() -> Result<(), ReproError> {
    make().whatever_context("bang")?;

    Ok(())
}