`Display` implementation for `toml_edit::Document` produces an empty string
The code below prints an empty string.
fn main() {
let toml = r##"
[project]
x = "y"
"##;
let doc = toml.parse::<toml_edit::Document<String>>().unwrap();
println!("{}", doc.to_string());
}
If I remove the project header it seems to print the key and value pair. DocumentMut also works perfectly fine.
#!/usr/bin/env nargo
---
[dependencies]
toml_edit = "0.23"
---
fn main() {
let toml = r##"
[project]
x = "y"
"##;
let doc = toml.parse::<toml_edit::Document<String>>().unwrap();
println!(
"---Document
{}
---",
doc.to_string()
);
let doc = toml.parse::<toml_edit::DocumentMut>().unwrap();
println!(
"---DocumentMut
{doc}
---"
);
}
I also switched it to [email protected] and Document with ImDocument and got the same result.
its important to note that there is no impl Display for Document. You can't move "{]", doc to "{doc}". The to_string function must be coming from the deref to the underlying table.
When we print a table, we don't recurse into sub-tables and print those. Since no keys are in the root of the document, we print nothing.
Going to need to put more thought into this for how this should be fixed.
Also encounter this within AI generated test code.
Maybe Document should not have .to_string() method which confuse AI, or just render non empty string.
let toml_string = doc.to_string();
let parsed_doc: Document<String> = toml_string.parse()?;
assert_eq!(doc.to_string(), parsed_doc.to_string());
assertion `left == right` failed
left: "XXX"
right: ""
let toml_string = doc.to_string();
let parsed_doc: Document<String> = toml_string.parse()?;
let parsed_doc = parsed_doc.into_mut();
assert_eq!(doc.to_string(), parsed_doc.to_string());