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

Add indexmap feature #21

Merged
merged 2 commits into from
Oct 16, 2021
Merged

Add indexmap feature #21

merged 2 commits into from
Oct 16, 2021

Conversation

vthib
Copy link
Contributor

@vthib vthib commented Oct 14, 2021

Add an optional indexmap feature to use an IndexMap instead of HashMap.
This is quite straightforward, the only thing of note is that the unparse method has been modified to avoid the clone/remove which does not mesh nicely with IndexMap.

Closes #19

@QEDK
Copy link
Owner

QEDK commented Oct 15, 2021

@vthib have you run the tests for this, I am having a hard time figuring out why Travis won't run tests...

@vthib
Copy link
Contributor Author

vthib commented Oct 15, 2021

I have yes, but I should add steps using --feature indexmap to the .travis.yml. I think you need to check on the travis-ci.com why the build did not trigger, every seems fine on the repo

@QEDK
Copy link
Owner

QEDK commented Oct 15, 2021

I have yes, but I should add steps using --feature indexmap to the .travis.yml. I think you need to check on the travis-ci.com why the build did not trigger, every seems fine on the repo

I will change this to GitHub Actions, and see if that works.

@@ -160,6 +160,12 @@ fn main() -> Result<(), Box<dyn Error>> {
```
The `Ini` struct offers great support for type conversion and type setting safely, as well as map accesses. See the API for more verbose documentation.

## 📖Features

- *indexmap*: Activating the `indexmap` feature allows using [indexmap](https://crates.io/crates/indexmap) in place
Copy link
Owner

@QEDK QEDK Oct 15, 2021

Choose a reason for hiding this comment

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

Could you also add the performance disparity? Maybe something like:
"Due to the nature of indexmap, it offers mostly similar performance to stdlib HashMaps but with slower lookup times."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@QEDK
Copy link
Owner

QEDK commented Oct 15, 2021

@vthib you need to run rustfmt it seems :)

The python configparser module uses ordered dictionaries, so that
a round-trip through a load/write keeps the same order of sections and
keys.
In Rust, the std HashMap does not keep insertion order, and actually
uses a hash that will change the order of iteration on subsequent runs.

When an INI file is to be read and/or modified by a user, it is much
preferable to keep the keys in order, as is done in python.
To do so however, a dependency is needed. `indexmap` is a popular crate
for this, that took inspiration on python's OrderedDict to create
a map tracking insertion order.

Use it in this crate, but only if a feature is activated. This keeps
the previous behavior intact, and does not bring a dependency unless
it is opted in.

The changes in themselves are very simple, as the APIs are similar.
The only change of not is in the unparse method, where the map was
cloned but most importantly, the default section was removed from the
clone. This remove messes up the order tracked by indexmap, so instead,
do not clone the map, but filter out the default section.
@vthib
Copy link
Contributor Author

vthib commented Oct 16, 2021

@vthib you need to run rustfmt it seems :)

Done!

@QEDK
Copy link
Owner

QEDK commented Oct 16, 2021

@vthib you need to run rustfmt it seems :)

Done!

Solid stuff, I'll be slating this for a 3.0 release in the coming week.

@vthib
Copy link
Contributor Author

vthib commented Oct 16, 2021

I'll push a PR for #18 as well. Is it possible to merge those two PR first? That way i can do the PR on master without having to deal with conflicts

@QEDK QEDK added this to the v3.0.0 milestone Oct 16, 2021
@QEDK
Copy link
Owner

QEDK commented Oct 16, 2021

I'll push a PR for #18 as well. Is it possible to merge those two PR first? That way i can do the PR on master without having to deal with conflicts

I will be merging this soon, please don't work on #18 yet as I am not sure if it's something that is absolutely needed.

@QEDK QEDK merged commit d7d1ad6 into QEDK:master Oct 16, 2021
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.

Keys are shuffled when loading and saving a INI file
2 participants