shepmaster / snafu

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

Allow `context(suffix)` on enum #304

Closed hellow554 closed 2 years ago

hellow554 commented 2 years ago

The example shows how to disable the context suffix for every enum variant. However, I'd like to disable it completly for the complete enum. In the case of the example I would like to write:

#[derive(Debug, Snafu)]
#[snafu(context(suffix(false)))]
enum Error {
    #[snafu(context(suffix(Ctx)))]
    HasAnotherSuffix,
    DoesNotHaveASuffix,
    DoesNotHaveASuffixEither,
}

The current error is:

error: context attribute is only valid on enum variants or structs with named fields, not on an enum

shepmaster commented 2 years ago

Seems reasonable as an upgrade path.

shepmaster commented 2 years ago

Can you try out the linked PR and see if it does what you'd expect?