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

Implement `snafu(transparent)` #409

Closed seritools closed 9 months ago

seritools commented 11 months ago

Fixes #406

netlify[bot] commented 11 months ago

Deploy Preview for shepmaster-snafu ready!

Name Link
Latest commit a021910c88649e8f9e758b0c78630de23b608312
Latest deploy log https://app.netlify.com/sites/shepmaster-snafu/deploys/656557e3d3d51f00086a56b9
Deploy Preview https://deploy-preview-409--shepmaster-snafu.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

seritools commented 10 months ago

I think everything should be fixed up now - rewrote the docs and added an example. Added another validation for transparent NAND display(...).

shepmaster commented 9 months ago

how different is this implementation from what we do for an opaque error? Should there be some sort of unification?

TL;DR: Probably, but not too worried about it right now. We will want to revisit this when we support enums with tuple variants.

These are basically the same:

struct MyError(YourError);

#[snafu(transparent)]
struct MyError { source: YourError }

I think we should make these two the same:

enum MyError {
    MyError(YourError),
}

enum MyError {
    #[snafu(context(false))]
    MyError { source: YourError },
}

However, that would mean that our opaque errors, which are tuple structs / struct MyError(YourError), would differ from tuple struct enum variants by the transparent. We should figure out how to perform some sort of reasonable migration.