-
-
Notifications
You must be signed in to change notification settings - Fork 224
Derive Hash
for integer Vector types
#356
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
Conversation
Hm, do you think it would be better for us to reuse godots hash implementation here? |
I think for more complex data types such as Vector2 or a general (macro assisted) solution, yes, because e.g. But for this specific case deriving should be fine as hashes are never shared across the FFI-Interface (correct me if I'm wrong) and there are no conventions to consider. A convention would be the case of a |
API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-356 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like a useful addition, thanks! One minor comment (please amend the 1 commit instead of adding a new one).
As for the question whether we should use Godot's hash, it's probably a wider discussion. Things to consider:
Eq
+Hash
+Ord
must play together in a consistent way.- If we use Godot's impl, we need to either call FFI or maintain a separate implementation, both of which come with drawbacks.
- Godot's impl may have different trade-offs regarding performance or security (not sure how applicable in gamedev domain, but something to keep in mind).
- At the moment,
Variant::from(x)
andx
have different hashing and equality relations, which may or may not be OK.
These are for a separate discussion though; a feature request with use case + rationale would be nice. Either way, making integer vectors hashable is relatively uncontroversial. The implementation can also be changed later, which should be transparent to the user. Or we could consider adding special functions or wrapper types for Godot-based equality/ordering/hashing.
@@ -21,7 +21,7 @@ use std::fmt; | |||
/// required. Note that the values are limited to 32 bits, and unlike [`Vector2`] this cannot be | |||
/// configured with an engine build option. Use `i64` or [`PackedInt64Array`] if 64-bit values are | |||
/// needed. | |||
#[derive(Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)] | |||
#[derive(Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Hash
should come before Debug
.
(I still need to write these conventions down somewhere...)
c6339ea
to
a2e6f0c
Compare
Thanks! |
Related: #297
My Usecase: Putting
Vector2i
's in aHashMap