-
Notifications
You must be signed in to change notification settings - Fork 140
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
The feature preserve_order
is not "purely additive," which makes it impossible to use serde_yaml
0.5.0 and clap
in the same program
#44
Comments
I think making 'preserve-order` as a default feature (or a must) will solve the problem. Few users has any reasons to disable this feature. What do you think? I would also like to hear from |
Sadly, I don't think this will be enough to avoid all problems (though it might help a little bit in some common cases). If I understood sfackler correctly, then turning on a feature can add new APIs. But if it changes or removes APIs, then cargo can't handle it correctly, and it may be impossible to use the library successfully in some projects. I wish I had a better answer here. Maybe it would be possible to offer both versions in the same API somehow? Or to always provide the ordered version, and to have a feature to turn on the unordered version without turning off the ordered version? Another possibility would be to provide just the ordered version all the time. This would be a breaking API change, so it would require releasing an 0.4.0 version. Those are the only ideas I can think of right now. There might be somebody on #cargo on the Mozilla IRC who could suggest other ideas. Anyway, thank you very much for releasing this library. It's extremely useful, and a lot of other great libraries rely on it! |
+1 for always using LinkedHashMap without an option to use BTreeMap. I used to provide a preserve_order feature flag in serde_yaml but dropped it in favor of always preserve_order. The behavior is more intuitive when serializing structs: fields are serialized in the same order they are defined in Rust, which matches the behavior of other Serde formats. Preserve order also allows a YAML document to be deserialized and re-serialized without affecting the order of map keys. |
While we're considering the map type anyway, |
CC @kbknapp There's a discussion that might be relevant for clap-rs/clap#747 happening on #44. I would personally be OK with only supporting |
OrderMap is immature (no reserve, shrink_to_fit, no .drain()) and obviously not a drop in for linkedhashmap, but it could be useful if you just want to preserve insertion order (just don't do any deletions, and it's preserved), not keep a double ended queue like linked hash map does. What are the common operations on it? If you know the number of key-value pairs to insert up front, I think insertion is the same cost as HashMap, if you grow dynamically, OrderMap should win slightly. OrderMap's iterators are very efficient (compared to HashMap), so if that is the main workload, then it could be a huge win. |
I'm not against changing clap to use the The temporary work around is for clap users to pin |
I've come across a conflict trying to use log4rs, which imports serde_yaml which in turn always has |
This has been closed, but it doesn't seem to be in a release yet? So dependent crates can't use the fix yet. Any plans for when that's gonna happen? |
Thank you for writing a great YAML parser for Rust! I'm working on several programs which make heavy use of it.
I ran into a rather tricky problem this morning, when I tried to use two Rust crates in the same program. And I'd love to get your feedback on it:
serde_yaml
0.5.0 requires thatyaml-rust
be configured with the featurepreserve_order
enabled.clap
requires thatyaml-rust
be configured withpreserve_order
disabled.Trying to use both crates in the same program will turn on
preserve_order
and breakclap
:I asked the Cargo maintainers on IRC if there was any workaround for this, and they said:
As I understand it, this means that if a feature is enabled, it shouldn't change any of the existing APIs of the crate. I'm not sure what the best solution is here.
I've filed related issues against the affected projects: clap-rs/clap#747 dtolnay/serde-yaml#33
Thank you for any suggestions you can provide, and for writing a great YAML parser for Rust!
The text was updated successfully, but these errors were encountered: