feat(uri): derive equality for URI errors#850
Draft
joshka wants to merge 1 commit into
Draft
Conversation
Allow InvalidUri and InvalidUriParts to implement PartialEq and Eq so library error types that wrap them can derive equality for tests. Keep ErrorKind private and leave broader error-type equality as a separate API question.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
I opened #849 as the durable place for the API tradeoff. This PR is a small concrete version of the change so maintainers can evaluate the actual patch shape.
I have a library error type that wraps
http::uri::InvalidUri. I would like that error type to derivePartialEqandEqfor straightforward unit tests, butInvalidUricurrently prevents that.Change
This derives
PartialEqandEqforInvalidUriandInvalidUriParts.ErrorKindremains private.The test checks that both public error types implement
Eqand that repeatedInvalidUri/InvalidUriPartsfailures can be compared directly.Compatibility
I realize this is still a public contract. Prior discussions such as #128 and #204 were cautious about trait impls on error types because they can constrain future internals.
My take is that
PartialEq/Eqis a smaller commitment thanClone: it does not exposeErrorKind, and equality can remain a coarse comparison over the existing broad URI error category. That said, users could observe whether twoInvalidUrivalues compare equal, so I am opening this as a draft PR to get maintainer feedback on that tradeoff.Refs #849.
Validation