zonyitoo / rust-ini

INI file parser in Rust
MIT License
305 stars 79 forks source link

feat(fmt): support fmt::Writers when writing ini to a Writer #131

Open iiian opened 6 months ago

iiian commented 6 months ago

Allows for

ini.to_string()
ini.write_to_fmt(&mut std::fmt::Writer)
ini.write_to_policy_fmt(&mut std::fmt::Writer, EscapePolicy)
ini.write_to_opt_fmt(&mut std::fmt::Write, WriteOption)

Context

I'm working with a very laggy remote Windows file system. Each individual R/W request has about 2 seconds delay before actually getting serviced. This means the streaming write!-based implementation of write_to_opt() is resulting in something like an O(n) slow-down where n is the # lines in the file. Introducing a fmt::Writer version, write_to_opt_fmt, lets me buffer the entire ini as a String and then fire it in one shot, resulting in a 75x performance improvement in my test scenario with an INI 462 lines long.

zonyitoo commented 6 months ago

Please resolve the windows CI build failure (\r\n issue).

zonyitoo commented 6 months ago

Still broken.

iiian commented 6 months ago

Hrm... I'm just not sure why this isn't working. I loaded rust-ini up on my Windows 11 machine, with supporting VisualC++ tooling -- all the unit tests are still passing. It seems to boil down to my inability to get the rust runtime to treat

r"
hello
world
"

as having CRLFs, even though there are unit tests above mine that seemingly do the exact same thing.

Any ideas?

zonyitoo commented 5 months ago

You may consider add an option to the write_to_fmt call, which will force line-break to use \n.