feat(uri): derive equality for URI errors#850
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.
|
Thanks for considering this. I looked further into the concern that implementing equality could constrain future internal changes. One relevant standard-library precedent is I did not find an explicit discussion of equality in those reviews, so I would not claim that this settles the question for My practical motivation remains that That said, the downstream workaround is reasonable, and I understand the preference not to add the contract. I’m happy to leave this undone and close the PR. |
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