I’m trying to find an implementation of a set that maintains its insertion order when iterated. In my particular case it’s needed for encoding a preference for a set of values. I could abuse a BTreeMap, I suppose, but it’d be nicer to not. Does anyone know of an implementation?
Note that removal perturbs insertion order with ordermap - https://crates.io/crates/linked-hash-map is another option that avoids that caveat if it matters to you.
@sfackler Ta. Nice to know there’s two alternatives. In the last 10 years or so, I’ve only very occasionally needed remove on a map or set.
@arthurprs I’ve used OrderMap now and it does the ticket very nicely. Sadly, I’ve now got to write custom serde serialization logic for the places that use it, but that’s life…
@raphcohn would you be able to submit a PR to the ordermap crate with the Serde impls you wrote? I needed it today as well. Serde could be an optional dependency of ordermap.
My impls aren’t performant enough - they cheat by converting to and from other types that Serde already supports.