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

Replacing toml-rs to toml_edit (question) #239

Closed
GabrielBG0 opened this issue Oct 17, 2021 · 2 comments
Closed

Replacing toml-rs to toml_edit (question) #239

GabrielBG0 opened this issue Oct 17, 2021 · 2 comments

Comments

@GabrielBG0
Copy link

Hey guys, I'm working on replacing toml-rs for the ability to preserve the order and comments on the file, so toml_edit looked like the perfect tool for it.
I tried to use the easy module, because i thought that it was the toml-rs api but with the toml_edit behaviour, so I wouldn't have to change much code, since the code base written with toml-rs is quite large, but it kept the toml-rs behaviour of getting rid of comments and changing the order of things.
So, what I wanted to ask you guys is if the easy module is meant to preserve comments and like the “main” library or is it supposed to work exactly as toml-rs? And if easy is tooml-rs inside toml_edit, do you guys have any advice on replacing toml-rs?

@epage epage closed this as completed in ccd8336 Oct 18, 2021
@epage
Copy link
Member

epage commented Oct 18, 2021

Thats a good question that I overlooked in the docs and have since rectified it.

toml_edit::easy is meant for when want toml-rs and toml_edit but want either consistency in behavior or to keep your number of dependencies low. The design of toml-rs prevents us from this being format-preserving.

I will say the toml_edit API has gotten easier over time.

do you guys have any advice on replacing toml-rs?

Porting toml-rs code to toml_edit?

My first would be to only focus on doing that where its needed. If you have places where you only read TOML, feel free to keep that using toml-rs.

Beyond that,

  • Check your use of serde. We can't preserve formatting through that, though we could make it easier to insert chunks of new TOML data into a format-preserving Document via serde
  • If you are using the toml::Value API, the toml_edit::Document API won't be too different. The biggest issue will be that we have two table types, Table and InlineTable and two array types, Array and ArrayOfTables. TableLike and our Index / IndexMut APIs help gloss over some of these details.

@GabrielBG0
Copy link
Author

Thanks! This was really helpful, i really appreciate the time!

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

No branches or pull requests

2 participants