-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: derive Eq and Hash trait for messages where possible
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.
- Loading branch information
1 parent
86f87a2
commit 3562a58
Showing
10 changed files
with
77 additions
and
45 deletions.
There are no files selected for viewing
This file contains 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
10 changes: 5 additions & 5 deletions
10
prost-build/src/fixtures/field_attributes/_expected_field_attributes_formatted.rs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
// This file is @generated by prost-build. | ||
#[derive(Clone, PartialEq, ::prost::Message)] | ||
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)] | ||
pub struct Container { | ||
#[prost(oneof = "container::Data", tags = "1, 2")] | ||
pub data: ::core::option::Option<container::Data>, | ||
} | ||
/// Nested message and enum types in `Container`. | ||
pub mod container { | ||
#[derive(Clone, PartialEq, ::prost::Oneof)] | ||
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Oneof)] | ||
pub enum Data { | ||
#[prost(message, tag = "1")] | ||
Foo(::prost::alloc::boxed::Box<super::Foo>), | ||
#[prost(message, tag = "2")] | ||
Bar(super::Bar), | ||
} | ||
} | ||
#[derive(Clone, PartialEq, ::prost::Message)] | ||
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)] | ||
pub struct Foo { | ||
#[prost(string, tag = "1")] | ||
pub foo: ::prost::alloc::string::String, | ||
} | ||
#[derive(Clone, PartialEq, ::prost::Message)] | ||
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)] | ||
pub struct Bar { | ||
#[prost(message, optional, boxed, tag = "1")] | ||
pub qux: ::core::option::Option<::prost::alloc::boxed::Box<Qux>>, | ||
} | ||
#[derive(Clone, Copy, PartialEq, ::prost::Message)] | ||
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)] | ||
pub struct Qux {} |
4 changes: 2 additions & 2 deletions
4
prost-build/src/fixtures/helloworld/_expected_helloworld_formatted.rs
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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