-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Implement PartialEq
for http::Status
with derive macro
#2844
Comments
Yes, we should do this. This is an artifact of |
As an addendum, we should also derive |
I'm eager to do the PR, should I also include |
Yeah, might as well. |
# Main Reasoning `PartialEq` when not implemented via derive macro, lacks `StructuralPartialEq`. It causes undesired side effect, that the compiler rejects constants like `Status::Unauthorized` to be used in pattern (for example in the `match` expression) # Solution Because the current manual implementation is trivial and matches derived code 1:1, we can replace it with `#[derive]` without changes in the behaviour Fixes rwf2#2844
`PartialEq` when not derived results in `StructuralPartialEq` not being implemented. As this was the case for `http::Status`, matching against constants like `Status::Unauthorized` was not allowed. This commit replaces the manual implementations of equality traits (`PartialEq`, `Eq`) and ordering traits (`PartialOrd`, `Ord`) for `http::Status` with `#[derive]`. Resolves rwf2#2844.
`PartialEq` when not derived results in `StructuralPartialEq` not being implemented. As this was the case for `http::Status`, matching against constants like `Status::Unauthorized` was not allowed. This commit replaces the manual implementations of equality traits (`PartialEq`, `Eq`) and ordering traits (`PartialOrd`, `Ord`) for `http::Status` with `#[derive]`. Resolves rwf2#2844.
API Docs to Existing Functionality
https://api.rocket.rs/v0.5/rocket/http/struct.Status
Problems with Existing Functionality
Status does not implement
PartialEq
viaderive(PartialEq)
, which causes it to lackStructuralPartialEq
.It prohibits using status in match:
because
Status::Unauthorized
is a constant which triggers error:Suggested Changes
I've looked at current implementation of
PartialEq
forStatus
:https://github.com/rwf2/Rocket/blob/1a3ef5b23fdf4a4619fa9b5d3f24cff6f8008085/core/http/src/status.rs#L363C1-L367C2
And it seems that there is nothing prohibiting automatic derive.
Alternatives Considered
An alternative solution to my
match
expression is something like this:But it doesn't feel idiomatic.
Another would be to use code directly:
But here I'm more prone to the typo than using existing constant.
Additional Context
No response
System Checks
I do not believe that this suggestion can or should be implemented outside of Rocket.
I was unable to find a previous suggestion for this change.
The text was updated successfully, but these errors were encountered: