Closed NobodyXu closed 2 years ago
It's not an optimization. Note the comment on the use
:
use std::collections::BTreeMap; // Used to preserve key ordering in Debug output
Sorry I didn't notice that.
That said, that may not be quite accurate.
I'm used to manually keeping my keys alphabetized and I think, since I wrote that snippet, I discovered that it's actually enforcing a sort order which just happens to be what I was doing by hand.
I'll need to double-check that but, either way, it ensures the Debug
output is more deterministic.
EDIT: Yeah. I've pushed a correction to the comment.
...but you did remind me of something I'd have forgotten to use if I chose to derive(Serialize)
.
TOML requires you to #[serde(serialize_with = "toml::ser::tables_last")]
your maps to reconcile Serde's behaviour with one of TOML's more unusual validity requirements.
I believe use of
BTreeMap
insrc/config.rs
is an immature optimization, sinceHashmap
should be more than enough for this scenario.