enumflags2 icon indicating copy to clipboard operation
enumflags2 copied to clipboard

The `std` feature is not discoverable (was: `FromBitsError` doesn't implement `Error`)

Open drewcassidy opened this issue 2 years ago • 3 comments

enumflags2 uses FromBitsError for the error for TryFrom, but the struct doesnt implement std::error::Error which makes it unwieldy to use, for example with the ? operator or a diagnostics package like Miette

45  | pub struct FromBitsError<T: BitFlag> {
    | ------------------------------------ doesn't satisfy `_: Error`
    |
    = note: the following trait bounds were not satisfied:
            `FromBitsError<DDSPixelFormatFlags>: std::error::Error`
            which is required by `Result<BitFlags<DDSPixelFormatFlags, u32>, FromBitsError<DDSPixelFormatFlags>>: IntoDiagnostic<BitFlags<DDSPixelFormatFlags, u32>, FromBitsError<DDSPixelFormatFlags>>`

drewcassidy avatar Jun 30 '23 07:06 drewcassidy

You need to enable the std feature on enumflags2. Though, good point, this is not entirely discoverable, and perhaps the feature should be enabled by default.

meithecatte avatar Jun 30 '23 08:06 meithecatte

Marking this as breaking change, as enabling the std feature by default would require action from everyone who's using the library on #![no_std]

meithecatte avatar Jun 04 '24 17:06 meithecatte

Makes sense. I think it really just needs a more helpful error message but that's more a complaint for the rust compiler team

drewcassidy avatar Jun 04 '24 18:06 drewcassidy