toml
toml copied to clipboard
Replacing an `InlineTable` with a comment with a `Table` results in invalid syntax
use std::str::FromStr;
use toml_edit::{Document, Item, Table};
fn main() {
let mut val = Document::from_str(
r#"
# hello i'm a comment
foo = { bar = 1 }
"#,
)
.unwrap();
println!("before: {}", val.to_string());
let mut new_foo = Table::new();
new_foo.insert("bar", Item::Value(1.into()));
new_foo.insert("baz", Item::Value(2.into()));
*val.get_mut("foo").unwrap() = Item::Table(new_foo);
println!("after: {}", val.to_string());
}
Expected output:
before:
# hello i'm a comment
foo = { bar = 1 }
after:
# hello i'm a comment
[foo]
bar = 1
baz = 2
Actual output:
before:
# hello i'm a comment
foo = { bar = 1 }
after: [
# hello i'm a comment
foo ]
bar = 1
baz = 2