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

epoch: derive Hash #170

Merged
merged 3 commits into from Nov 6, 2022
Merged

epoch: derive Hash #170

merged 3 commits into from Nov 6, 2022

Conversation

gwbres
Copy link
Collaborator

@gwbres gwbres commented Nov 6, 2022

Hash is required if we want structures like "HashMap" or "BTreeMap"
indexed by an Epoch

Signed-off-by: Guillaume W. Bres guillaume.bressaix@gmail.com

Hash is required if we want structures like
"HashMap" or "BTreeMap" indexed by an `Epoch`

Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
@ChristopherRabotin
Copy link
Member

Thanks! That is definitely useful.

I'm not sure why Clippy doesn't like it. Here is the explanation: https://rust-lang.github.io/rust-clippy/master/index.html#derive_hash_xor_eq . Any idea how to fix this? Should Hash be implemented manually instead of derived? I want to keep the PartialEq and Eq "derivations" for backward compatibility (and it's a feature I use a lot).

Implement Hash ourselves so it is consistent with PartialEq

Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
@gwbres
Copy link
Collaborator Author

gwbres commented Nov 6, 2022

Hello @ChristopherRabotin

Any idea how to fix this? Should Hash be implemented manually instead of derived? I want to keep the PartialEq and Eq "derivations" for backward compatibility (and it's a feature I use a lot).

https://www.philipdaniels.com/blog/2019/rust-equality-and-ordering/

My mere understanding is that Hash and Eq are closely related.
When implementing Eq yourself you can do whatever you want, like disregarding inner objects contained in a structure.
An example would be a Duration equality, based only off "centuries".
But auto derivation / auto implementation makes use of all inner objects (I presume).
So one must be very careful when mixing Auto and self implemented traits like this, especially these two that intend to work on the same variables/conditions

@codecov-commenter
Copy link

codecov-commenter commented Nov 6, 2022

Codecov Report

Base: 78.79% // Head: 78.57% // Decreases project coverage by -0.21% ⚠️

Coverage data is based on head (0a1b05d) compared to base (0b25940).
Patch coverage: 12.50% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #170      +/-   ##
==========================================
- Coverage   78.79%   78.57%   -0.22%     
==========================================
  Files           9        9              
  Lines        2579     2586       +7     
==========================================
  Hits         2032     2032              
- Misses        547      554       +7     
Impacted Files Coverage Δ
src/duration.rs 83.90% <0.00%> (-0.62%) ⬇️
src/epoch.rs 86.34% <0.00%> (-0.21%) ⬇️
src/timescale.rs 90.54% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@ChristopherRabotin
Copy link
Member

ChristopherRabotin commented Nov 6, 2022

Perfect, I think that implementing the hasher manually works well (and makes clippy happy). Also, the Epoch hash is based only on the duration since J1900 TAI, which is what the equality checks too, so that's the correct behavior. Thanks!

@ChristopherRabotin ChristopherRabotin merged commit ed2090d into nyx-space:master Nov 6, 2022
@gwbres gwbres deleted the hash branch November 15, 2022 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants