-
Notifications
You must be signed in to change notification settings - Fork 90
[DRAFT] indexmap support #436
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
base: main
Are you sure you want to change the base?
Conversation
0984f6d to
bcbc2c8
Compare
bcbc2c8 to
f3f556e
Compare
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.
This completely ignores the discussion in the issue
|
Sorry Heinz, what do you mean? I outlined my approach here as 2 steps, and you accepted the PR in value-trait with the first one, which this uses as its follow-on 2nd step. What part did I miss? Do you mean this comment?
I took that last sentence to mean that the way I had outlined was okay, is this not what you had in mind? edit oh, sorry I misread that as saying the approach I had or an alternative parameterising the type would both be okay, I see now you were actually suggesting 2 alternatives. Gotcha I submitted this PR 6 hours ago and you replied 4 hours ago so I wasn't ignoring your comments, just looks like I implemented the wrong way 😞 |
450cfed to
75b7c62
Compare
This comment was marked as resolved.
This comment was marked as resolved.
18a1c88 to
f8c939a
Compare
f8c939a to
d99ead1
Compare
d99ead1 to
696b542
Compare
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.
Sadly we're living in a time where I've to write reviews like this but I'm getting the strong feeling you're throwing an AI at this problem without thinking or reviewing your own PR.
If that's the case please just close the PR, I'm neither interested nor willing in reviewing 7000 LOC AI slop nor taking on the maintenance burden of it
| let v_simd_borrowed = to_borrowed_value(d3).expect("to_borrowed_value failed"); | ||
| assert_eq!(v_simd_borrowed, v_simd_owned); | ||
| let v_deserialize: OwnedValue = deserialize(d4).expect("deserialize failed"); | ||
| let v_deserialize: OwnedValue = deserialize::<OwnedValue, String>(d4).expect("deserialize failed"); |
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.
What change does require adding the types here? I'm somewhat concerned that this might become required for callers and affect the API negatively.
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.
Mhm I agree, I think this came up while iterating on either the new ordered Value serde de.rs impls or ordered/from.rs ones (and making sure they didn't clash and give "duplicate impl" error)
I just tried removing it and it gave this, that was the cargo directive I followed:
error[E0283]: type annotations needed
--> src/tests/serde.rs:1011:45
|
1011 | let v_deserialize: OwnedValue = deserialize(d4).expect("deserialize failed");
| ^^^^^^^^^^^ cannot infer type of the type parameter `Key` declared on the function `deserialize`
|
= note: cannot satisfy `_: Hash`
note: required by a bound in `value::deserialize`
--> src/value.rs:116:10
|
113 | pub fn deserialize<'de, Value, Key>(s: &'de mut [u8]) -> Result<Value>
| ----------- required by a bound in this function
...
116 | Key: Hash + Eq + From<&'de str>,
| ^^^^ required by this bound in `deserialize`
help: consider specifying the generic arguments
|
1011 | let v_deserialize: OwnedValue = deserialize::<value::owned::Value, Key>(d4).expect("deserialize failed");
| ++++++++++++++++++++++++++++
error[E0283]: type annotations needed
--> src/tests/serde.rs:1011:45
|
1011 | let v_deserialize: OwnedValue = deserialize(d4).expect("deserialize failed");
| ^^^^^^^^^^^ cannot infer type of the type parameter `Key` declared on the function `deserialize`
|
= note: multiple `impl`s satisfying `_: From<&str>` found in the `proptest` crate:
- impl From<&'static str> for Reason;
- impl From<&'static str> for StringParam;
note: required by a bound in `value::deserialize`
--> src/value.rs:116:22
|
113 | pub fn deserialize<'de, Value, Key>(s: &'de mut [u8]) -> Result<Value>
| ----------- required by a bound in this function
...
116 | Key: Hash + Eq + From<&'de str>,
| ^^^^^^^^^^^^^^ required by this bound in `deserialize`
help: consider specifying the generic arguments
|
1011 | let v_deserialize: OwnedValue = deserialize::<value::owned::Value, Key>(d4).expect("deserialize failed");
| ++++++++++++++++++++++++++++ | /// Hashmap used for objects | ||
| #[cfg(not(feature = "preserve_order"))] | ||
| type ObjectMap<K, V> = HashMap<K, V, ObjectHasher>; | ||
| /// Hashmap used for objects | ||
| #[cfg(feature = "preserve_order")] | ||
| type ObjectMap<K, V> = IndexMap<K, V, ObjectHasher>; |
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.
no.
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.
I'm aware! This is left over from the first rewrite as already discussed.
PR is WIP, hence I put it back in draft mode didn't mean for it to be reviewed yet. See comment
|
Sorry for the rudeness @lmmx |
|
Aha it's all good 😅 🙏 |

Summary
When the preserve_order feature is enabled, JSON objects now use IndexMap instead of HashMap to maintain insertion order. This is visible for objects with more than 32 keys, where halfbrown switches from Vec to HashMap.
Key changes
Fixes ordering issue for objects with 33+ keys when preserve_order
feature is enabled.
Success 🎉
Tests pass both with and without the new feature flag
cargo nextest run -F preserve_order -E 'test(preserve_order)'Full suite:
-F preserve_orderRewrite
Components implemented
✔️ Compatible with all features
Status
deserializefunctions. These functions need to work with both ordered and non-ordered types, depending on what the caller wants. So de/serialisation will either need to get additional separate deserialise functions for ordered types, or the existing ones should work generically with both.