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

Add a way to customize the literal-ness (single/double quotes) of a string #590

Open
sunshowers opened this issue Jul 28, 2023 · 4 comments
Labels
A-edit Area: TOML editing API C-enhancement Category: Raise on the bar on expectations

Comments

@sunshowers
Copy link
Contributor

sunshowers commented Jul 28, 2023

Hi everyone (and epage in particular), thanks for all your hard work on toml! Really appreciating all the work y'all have done integrating toml_edit and toml.

For guppy, tried upgrading toml to 0.7 and sadly ran into a deal-breaking issue. Guppy currently produces output that has single quotes in it, e.g. this file. When I migrate to toml 0.7, it becomes double-quoted as seen in https://gist.github.com/sunshowers/0ed4ab2143ea1efa8afb10f1a500e61e#file-gistfile0-txt-L4-L28.

The output format cannot be changed for backwards compatibility reasons -- these files are checked into repositories and one of the promises made by hakari is to not change how checked-in files are recorded.

So it seems like what I would need is a way to change how strings are recorded so that they're presented as single quotes.

I spent some time looking around and it looks like while this is supported internally, there's no API to access this. Value::String is a Formatted<String>, which doesn't seem to be high-enough fidelity. It seems like what we would really need is a StringWithQuotes or similar, which would track both the string as well as the quoting style.

What do you think? Without this, or some other solution, I'll have to be stuck at toml 0.5 forever. This would be a shame :(

@epage
Copy link
Member

epage commented Jul 28, 2023

Huh, looks like this is the first time someone has requested customizing of strings.

If backwards compatibility on formatting is important for you, I would recommend auditing for it any auto formatting because we do not guarantee compatibility on it.

I spent some time looking around and it looks like while this is supported internally, there's no API to access this. Value::String is a Formatted, which doesn't seem to be high-enough fidelity. It seems like what we would really need is a StringWithQuotes or similar, which would track both the string as well as the quoting style.

The way this would be handled is

impl Formatted<String> {
    pub fn style(&mut self, ...);
}

Which would overwrite the Repr stored inside the Formatted to preserve the information

I'm fine with doing this, we just need to work out the details of the API and make sure the string formatting is hardened enough to support this. By keeping it internal, I'm less likely to run into corner cases like someone over-specifying a string style that cannot be used.

@epage epage added C-enhancement Category: Raise on the bar on expectations A-edit Area: TOML editing API labels Jul 28, 2023
@sunshowers
Copy link
Contributor Author

sunshowers commented Jul 28, 2023

If backwards compatibility on formatting is important for you, I would recommend auditing for it any auto formatting because we do not guarantee compatibility on it.

Absolutely, we have a number of tests which catch issues related to backwards compatibility (not just formatting, but also ordering of table entries, and so on). Those tests are how I found out about this issue.

@epage
Copy link
Member

epage commented Sep 4, 2024

#781 is having a similar discussion but for integers.

@sunshowers
Copy link
Contributor Author

(Definitely something I still want, but toml 0.5 has been trucking along so it hasn't been a huge priority for me)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-edit Area: TOML editing API C-enhancement Category: Raise on the bar on expectations
Projects
None yet
Development

No branches or pull requests

2 participants