-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
[RUST] Add Eq and Hash Trait to Rust client struct to allow Hashset usage #20413
base: master
Are you sure you want to change the base?
[RUST] Add Eq and Hash Trait to Rust client struct to allow Hashset usage #20413
Conversation
@Snazzie thanks for the PR can you please review the CI failures when you've time? |
Hmm, my rust and mustache knowledge is a bit low. Im not sure the best way to support for number types (i16, f32 etc) with Eq and Hash. it looks like i have to do separate implements like so. where need conditional hash implementation on all properties. impl Eq for PizzaSpeziale {} if type is f64 impl Hash for PizzaSpeziale {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.pizza_size.map(|v| v.to_bits()).hash(state);
}
} if type is i32 impl Hash for PizzaSpeziale {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.pizza_size.map(|v| v.to_be()).hash(state);
}
} perhapse in mustache something like this impl Eq for {{{classname}}} {}
impl Hash for {{{classname}}} {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
// Combine hashes of all fields
{{#vars}}
{{#isInteger}}
self.{{name}}.map(|v| v.to_bits()).hash(state);
{{/vars}}
}
} or keep existing trait and use wrappers for number types. struct F64Wrapper(f64); |
what about using isLong and isShort in the template? e.g. Lines 96 to 101 in 3d65786
|
Am i alone in thinking that eq and hash should not be implemented by default? Im assuming your including all properties in the hash calculation, but what if the entity has an id property? I would expect only the id to be considered in the hash. Since we cant tell which properties are the id imho we should not implement hash or equals. |
I see your point, there can be different needs. However i think the most common expected behavior when you're doing equality comparison between two objects, every property is considered, especially in a hashset. And if you need a different equality behavior you would override or separately code it in consumer function. |
Resolves #20412
Hashset insert requires Eq and Hash traits.. This change will allow inserting generated struct into Hashsets.
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master
(upcoming7.x.0
minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)