Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide details of error implementation, to not make changes into breaking changes #57

Merged
merged 2 commits into from
Apr 11, 2024

Conversation

faern
Copy link
Member

@faern faern commented Apr 2, 2024

As discussed in the office. Having errors simply be public enums with associated data makes the implementation details part of the public API. Then almost all changes to the error are breaking changes. Here I show two potential ways to implement errors so that their internals are hidden, but it's equally easy to match for a library consumer.

This is currently split into two commits, one per proposed solution. So view it per commit if you want to compare them. I personally like the second solution the best. That error implementation could fairly easily be generated by a macro. I'm sure we are not the first people to come to this conclusion, maybe there is such a macro crate on crates.io already?


This change is Reviewable

@faern faern requested a review from hulthe April 2, 2024 15:41
@hulthe
Copy link
Contributor

hulthe commented Apr 2, 2024

I like 2 as well. Took the liberty of mocking up a solution that involves more macros (here).
Sadly this adds 2 more dependencies (thiserror and strum), but could be worth exploring.

@faern faern force-pushed the hide-error-impl-details branch from 7b8aa13 to 2ec515f Compare April 3, 2024 12:10
Copy link
Contributor

@hulthe hulthe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r2, 1 of 1 files at r3, 1 of 1 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @faern)

@faern faern force-pushed the hide-error-impl-details branch from 2ec515f to 77ee39d Compare April 11, 2024 11:41
@faern faern merged commit 75eb1fd into main Apr 11, 2024
12 checks passed
@faern faern deleted the hide-error-impl-details branch April 11, 2024 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants