nlfiedler / magick-rust

Rust bindings for ImageMagick
https://crates.io/crates/magick_rust
Apache License 2.0
254 stars 68 forks source link

std::error::Error compatible error handle? #86

Closed DCjanus closed 2 years ago

DCjanus commented 2 years ago

People using magick-rust and anyhow would suffer from error transform like this

fn foo() -> anyhow::Result<()> [
    magick_wand.some_method().map_err(|e|anyhow!())?
    Ok(())
}

If we are using Result type like this, things would be easier:

struct MagickError(&'static str);

impl From<&'static str> for MagickError {
    fn from(s: &'static str) -> Self {
        MagickError(s)
    }
}

fn foo1() -> Result<(), MagickError> {
    Err("something went wrong")?;

    Ok(())
}

fn foo2() -> Result<(), MagickError> {
    foo1()?;

    Ok(())
}

fn foo3() -> anyhow::Result<()> {
    foo2()?;

    Ok(())
}

I do believe there would be a lot of boring work, I'd like to handle this, since I really like this.