-
Notifications
You must be signed in to change notification settings - Fork 138
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-2027 Impl Hash/Eq for BSON #495
Conversation
* Added feature `hashable` (and to README.md). * `Bson::Double` - implemented the same solution as [`serde_json`](https://docs.rs/serde_json/1.0.127/src/serde_json/number.rs.html#53-70). * `Bson::Document(Document)` - implemented the same solution as [`serde_json`](https://docs.rs/serde_json/1.0.127/src/serde_json/map.rs.html#395-397). * `Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope)` - Able to impl Hash/Eq only if Document is impl Hash/Eq. * `Bson::{RegularExpression(Regex), Binary(Binary), Decimal128(Decimal128), DbPointer(DbPointer)}` - Added Derive Hash/Eq without feature flag `hashable`, no reason for it not to implement those by default.
Thank you for the well-thought-out PR! The changes look good to me and I've started a test run; once the tests pass and this is reviewed by another team member we'll merge it in. |
On the topic of switching |
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.
a few docs suggestions, otherwise looks good. thanks for your contribution!
Co-authored-by: Isabel Atkinson <[email protected]>
Co-authored-by: Isabel Atkinson <[email protected]>
#494
Summery of changes:
hashable
to require the user to choose to opt-in usingBson
as hash key.Although,
serde_json
didn't bother with having this behind the feature flag, so If you like I can remove it.Bson::Double(f64)
- implemented the same solution asserde_json
.Bson::Document(Document)
- implemented the same solution asserde_json
.Bson::JavaScriptCodeWithScope(JavaScriptCodeWithScope)
- Able to impl Hash/Eq only if Document is impl Hash/Eq.Bson::{RegularExpression(Regex), Binary(Binary), Decimal128(Decimal128), DbPointer(DbPointer)}
- Added Derive Hash/Eq without feature flaghashable
, no reason for it not to implement those by default.I didn't implement it yet, but if the above feature is acceptable,
it might be worth adding another feature like
not(preserve_order)
fromserde_json
,to change
Bson::Document
to useBTreeMap
instead ofindexmap
for more efficient hashing (likeserde_json
).I don't mind adding this as a separate PR.