tokio-rs / prost

PROST! a Protocol Buffers implementation for the Rust Language
Apache License 2.0
3.95k stars 506 forks source link

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

Open caspermeijn opened 1 month ago

caspermeijn commented 1 month ago

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:

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.

caspermeijn commented 2 days ago

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

I think you mean something like skip_debug but for these traits. I feel like always implementing Eq is acceptable, as that is also the case for PartialEq.

The disadvantage of a skip function is that the complexity is raised in the code generator.

LucioFranco commented 2 days ago

Yeah, I was thinking it may help for those backward compat issues.