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

feat: preserve_order feature #90

Closed
wants to merge 1 commit into from

Conversation

Ziqi-Yang
Copy link

Add preserve_order feature to preserve the map order.
I haven't add corresponding test to this library since compilation errors (for all tests) occurs when I run cargo test and I don't know the correct command to run those tests. However, I do have a test in my external test environment, and it works fine.

This feature solves #89

Comment on lines +10 to +15
#[cfg(not(feature = "preserve_order"))]
pub type Map<K, V> = BTreeMap<K, V>;

/// An alias to the type of map used in [`Value::Dict`].
#[cfg(feature = "preserve_order")]
pub type Map<K, V> = indexmap::IndexMap<K, V>;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot do this: features must be additive. This breaks that.

@SergioBenitez
Copy link
Owner

I'm okay with the idea in general, but this implementation is incorrect. If we're going to do this, the cost is making the map type opaque as otherwise we cannot switch the implementation via a feature. See how serde_json does this. We effectively need to do exactly that.

As you can see, this is rather unfortunate - there's a lot of duplication. The alternative is to always use IndexMap, but now we have a compile-time cost addition. I don't know of a good approach here.

@SergioBenitez
Copy link
Owner

Closing due to inactivity.

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.

2 participants