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

Decor in DocumentMut is ignored #727

Open
yyny opened this issue May 10, 2024 · 2 comments
Open

Decor in DocumentMut is ignored #727

yyny opened this issue May 10, 2024 · 2 comments
Labels
A-edit Area: TOML editing API C-enhancement Category: Raise on the bar on expectations

Comments

@yyny
Copy link

yyny commented May 10, 2024

Example

use toml_edit::*;

let mut document = DocumentMut::new();
document.decor_mut().set_prefix("# HEADER\n");
document.decor_mut().set_prefix("# FOOTER\n");
println!("{document}");

document.as_table_mut().insert("key", value("value"));
println!("{document}");

Expected

# HEADER
# FOOTER
# HEADER
key = "value"
# FOOTER

Actual

key = "value"
@epage
Copy link
Member

epage commented May 10, 2024

What this is hiding is that this isn't DocumentMut::decor_mut but Table::decor_mut that is being accessed due to a convenience Deref.

I don't think I'm against this. I'm also curious about collapsing trailing into the suffix. I'm not sure why that wasn't done before.

@epage epage added C-enhancement Category: Raise on the bar on expectations A-edit Area: TOML editing API labels May 10, 2024
@ysndr
Copy link

ysndr commented May 10, 2024

We did run into the same issue today (what a coincidence).
For now we only wanted to add a document wide header and probably going to resort to prepending it to the first item in the document, though adding it to the document directly would definitely be more ergonomic.

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

3 participants