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

feat: derive Eq and Hash trait for messages where possible #1175

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

caspermeijn
Copy link
Collaborator

Integer and bytes types can be compared using trait Eq. Some generated Rust structs can also have this property by deriving the Eq trait.

Automatically derive Eq and Hash for:

  • messages that only have fields with integer or bytes types
  • messages where all field types also implement Eq and Hash
  • the Rust enum for one-of fields, where all fields implement Eq and Hash

Generated code for Protobuf enums already derives Eq and Hash.

BREAKING CHANGE: prost-build will automatically derive trait Eq and trait Hash for types where all field support those as well. If you manually impl Eq and/or impl Hash for generated types, then you need to remove the manual implementation. If you use type_attribute to derive(Eq) and/or derive(Hash), then you need to remove those.

Integer and bytes types can be compared using trait Eq. Some generated Rust structs can also have this property by deriving the Eq trait.

Automatically derive Eq and Hash for:
- messages that only have fields with integer or bytes types
- messages where all field types also implement Eq and Hash
- the Rust enum for one-of fields, where all fields implement Eq and Hash

Generated code for Protobuf enums already derives Eq and Hash.

BREAKING CHANGE: `prost-build` will automatically derive `trait Eq` and `trait Hash` for types where all field support those as well. If you manually `impl Eq` and/or `impl Hash` for generated types, then you need to remove the manual implementation. If you use `type_attribute` to `derive(Eq)` and/or `derive(Hash)`, then you need to remove those.
Copy link
Member

@LucioFranco LucioFranco left a comment

Choose a reason for hiding this comment

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

LGTM, would it make sense to make these derives optional?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants