rust-ini icon indicating copy to clipboard operation
rust-ini copied to clipboard

Comments are not kept after write_to_file

Open lrascao opened this issue 3 years ago • 4 comments

[a_section]
a=1
#b=1

after write_to_file is called we end up with:

[a_section]
a=1

lrascao avatar Oct 16 '20 17:10 lrascao

Yup.. Comments are not kept after parsed. Any PRs are welcome.

zonyitoo avatar Oct 17 '20 10:10 zonyitoo

cool, could you please suggest an implementation strategy?

lrascao avatar Oct 19 '20 10:10 lrascao

I have no idea how to implement that gracefully, because comments may not be followed by a key-value pairs, or a section header, how to store it?

Do you know any other INI libraries that could kept comments after parsing? @lrascao

zonyitoo avatar Oct 19 '20 13:10 zonyitoo

I'm not familiar with rust-ini, but based on this issue alone, I assume it works by mapping the whole file on read, and flushing the whole structure into a file on write. Which will probably bite you when dealing with big files, so it may not be the best approach.

From Bash I use crudini which is in Python so prolly not much of a help, but who knows. All I know is it works just fine with comments. Basically it doesn't care about irrelevant sections in the file, or irrelevant lines in the section either. It touches only the parts you tell it touch.

bviktor avatar Mar 07 '23 01:03 bviktor