You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
views: generated view types do not implement PartialEq, Eq or Hash, and a build option cannot add them #705
A generated view derives Clone, Debug and Default (buffa-codegen/src/view.rs and lazy_view.rs; Debug is a manual impl when a field is redacted, and Default when the message has one); a view-of-oneof enum derives Clone and Debug. This holds for every message, the well-known types in buffa-types/src/generated/*.__view.rs included:
let a = TimestampView::decode_view(bytes_a)?;let b = TimestampView::decode_view(bytes_b)?;assert_eq!(a, b);// does not compileassert_eq!(a.to_owned_message(), b.to_owned_message());// the available form
The owned types derive PartialEq, and #685 adds Eq and Hash to the float-free well-known types; its changelog entry says "convert a view with to_owned_message to compare or hash it". type_attribute and message_attribute reach the owned struct only, so a build cannot add the derive to a view. OwnedView<V> already has PartialEq and Eq impls conditional on the view's (buffa/src/view.rs), which the guide notes apply only to hand-written views.
What a derive on views would need, from the field types in buffa/src/view.rs:
MessageFieldView<V> has PartialEq, Eq and Hash.
RepeatedView and MapView derive PartialEq and Eq, and do not implement Hash.
MapView's derived equality compares the decoded entry list in wire order, duplicates included. The owned map compares as a map, so view_a == view_b could differ from view_a.to_owned_message() == view_b.to_owned_message(), which is the agreement MessageFieldView's PartialEq doc promises.
UnknownFieldsView derives Clone and Default only. It holds borrowed spans of one or more records each, so equality has to compare records, not spans.
Questions:
Should views implement PartialEq (and Eq / Hash where the message is float-free) at all, given that to_owned_message gives the comparison at the cost of an allocation?
If so, is the contract "equal exactly when the owned messages are equal"? That needs map-semantic equality for MapView and record-wise equality for UnknownFieldsView.
Always generated, or behind a build option, to keep generated code size down for users who do not compare views?
Activity