Conversation

Nice, swift enums have the same functionality. However, at that point it seems to me the specific error type isn't doing much for your clients
3
1
Depends on the context. Diesel has an error variant for "this query was expected to return 1 or more rows, but zero were returned" for example which is commonly handled. Really the point is more than if your consumers can recover from a specific case, don't take the choice away
1
4
It seems like you don't need API-specific typed errors to achieve that, though. You could have something where there's one Error type but APIs can provide a nonexhaustive set of subtypes they may produce, for documentation purposes
1
Yeah, and that's roughly how the Error trait works in Rust actually. It's just not nearly as ergonomic as matching an enum
2
3
I've always thought the error trait is more for constructing error reports, the downcasting stuff is really the Any trait's responsibility but that couldn't be added as a super trait because Any has a 'static bound Matching against Any or Error does sound nice tho...
2
3
i had a great convo with a few months ago about how to match on trait objects like non exhaustive enums and how we might do derived “vtable impls” to let enums play as trait objects i had several other much worse ideas about enum/trait obj equivalence too
2
6
yeah imo enums should be traits over their variant types and basically just "inline trait objects", and we should get the exact same treatment in reverse
3
9
Show replies