Comments (9)
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 clap-rs
maintainers.
from yaml-rust.
What do you think?
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!
from yaml-rust.
+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.
from yaml-rust.
While we're considering the map type anyway, OrderMap
seems promising. I opened bluss/indexmap#9 to ask whether there are any disadvantages compared to LinkedHashMap.
from yaml-rust.
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 LinkedHashMap
or OrderMap
, even if it cost some performance. But I don't know everybody else's use cases.
from yaml-rust.
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.
from yaml-rust.
I'm not against changing clap to use the preserve_order
feature, but unfortunately doing so is breaking change for me and something I can't take lightly. I've had a 3.x version on the backburner for a while, and could make that change then, but it probably won't be for another few months until I have enough time to iron out the 3.x branch.
The temporary work around is for clap users to pin serde_yaml
to 0.4.1 until I can make the breaking change and bump the major version.
from yaml-rust.
I've come across a conflict trying to use log4rs, which imports serde_yaml which in turn always has preserve_order
enabled, and config-rs which hard-codes BTreeMap and doesn't expect preserve_order
to be enabled. This means I can use one library and not the other.
Anyhow, I was wondering what the progress on the PR is, the required change appears to have been made but isn't building and hasn't been accepted?
from yaml-rust.
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?
from yaml-rust.
Related Issues (20)
- Parse from raw bytes HOT 2
- Add more maintainers HOT 11
- Valgrind complains about uninitialized values HOT 4
- Add support for YAML 1.1 HOT 1
- Support alternate line endings
- Bug in anchor handling? HOT 2
- Panic uninitialised linked hash map HOT 2
- can not part ref HOT 1
- Doesn't seem possible to iteratate over results HOT 3
- misleading? HOT 1
- is it wasm compatible? HOT 1
- Dupliacte keys are not detected as invalid YAML
- Add API to emit YAML strings (i.e. `need_quotes` and `escape_str`)
- tabs are not allowed as the first character of a block scalar
- `Parser` parses empty scalar as '~' HOT 1
- Support no-std with alloc crate
- Integration with google oss-fuzz fuzzing service
- Maintainers HOT 8
- unsafe-libyaml looks... unsafe? HOT 1
- Dynamically choosing a YAML document path? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yaml-rust.