Would you consider modification of config files?
It's a project I'm currently planing but haven't really found how I want to do yet, and I stumbled upon this crate looking for a name.
Hi. I'm sorry but I think you need to provide a bit more context. What do you mean by "modification of config files"?
In the end, I want to provide a git config like sub command, that can set and query configuration values. But the need to modify the on disc configuration file can also arise from, e.g. GUI applications that have a settings menu on top of a human-readable on disc configuration file (e.g. VS Code).
Ah I see. That makes sense. This is something I very likely will consider for confique. In fact I might have this exact requirement very soon in one of my own projects in which I plan to use confique. So I will likely see about it then.
However, already now I am not sure how well confique can support it. Just serializing the whole configuration and writing it to the file again is fairly easy, but overwrites the whole file. That means that comments made by the user for example are overwritten. I am not sure confique will ever support this "only change what's necessary but keep the original file as much as possible". It's not easy. Would that be a requirement for you?
But yes, the basic "write an in-memory config to file" will certainly be supported. Likely also with the option to write or not write default values and the like.
I would want to keep comments and such, but that would require to not use serde for the writing but a different trait that could ask a Config provider to only write the changes but keep the rest of the file as is without breaking any formatting or comments. For toml this could be achieved with toml-edit and there are probably similar crates for other file formats, but this increases the custom code to maintain as one cannot rely on the serde infrastructure as much if at all.
Yep :/ I am very sure that confique will stay with serde and not pull in any other dependencies.
I experimented a bit, and it looks like it wouldn't be too terrible to do a serde serializer that preservers the original data if possible: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=dbda15adfbdf58defcaf2c5707a3a033
It uses toml-edit which would already be a dependency through toml.
Granted this is only a very incomplete implementation for toml one would need to repeat that for all supported data formats. But maybe there would be a way to design this in a way where these "modifying serializers" could be brought in externally from a confique consumer.