configparser-rs icon indicating copy to clipboard operation
configparser-rs copied to clipboard

Don't break semver compatibility when enabling a feature

Open Hofer-Julian opened this issue 10 months ago • 3 comments

Looking at the code, configparser changes the function signature depending on whether the indexmap feature is introduced.

https://github.com/QEDK/configparser-rs/blob/671c19cae9ca4cc473e01632219e1e1d427e4ae2/src/ini.rs#L3-L6

This shouldn't happen, according to the Cargo book: https://doc.rust-lang.org/cargo/reference/features.html#semver-compatibility

I think the proper way is to expose additional functions when the feature indexmap is enabled.

Hofer-Julian avatar Feb 24 '25 08:02 Hofer-Julian

For a bit of context: we encountered this issue since we had configparser twice in our dependency tree. Once with and once without indexmap enabled. This leads to Cargo compiling a single version with indexmap enabled. The crate that depended on configparser without indexmap therefore refused to compile since the function signature changed.

Hofer-Julian avatar Feb 24 '25 08:02 Hofer-Julian

For a bit of context: we encountered this issue since we had configparser twice in our dependency tree. Once with and once without indexmap enabled. This leads to Cargo compiling a single version with indexmap enabled. The crate that depended on configparser without indexmap therefore refused to compile since the function signature changed.

That's interesting but Rust does not give a good way for us to tackle this yet. This was the best idea when implemented because the user-facing API remains consistent. Having additional functions is not frictionless because the underlying structure needs to change regardless. Maybe a good idea is an enum-based attribute but this needs more thought imo. I will wait for more community input.

QEDK avatar Apr 27 '25 21:04 QEDK

Yeah, I don't think there's a way to fix this without a breaking change.

If you want to avoid duplicating functions at the API level, and probably neither internally, you could make a trait with all Map methods you use and make everything generic over that trait.

Hofer-Julian avatar Apr 28 '25 07:04 Hofer-Julian