commit | 20db17911dc856eefef9058804f30401ed0a3e7b | [log] [tgz] |
---|---|---|
author | Andrew Walbran <[email protected]> | Tue Nov 14 14:28:33 2023 +0000 |
committer | Automerger Merge Worker <[email protected]> | Tue Nov 14 14:28:33 2023 +0000 |
tree | bc9a93f9b6ee795502937b958fe2a7df6bce38f1 | |
parent | ceb9444e3f706febccabf0dd74c9bd370f7b2c8d [diff] | |
parent | 18ec38355d1586da23b6e3d70c12915caae6c16e [diff] |
Migrate to cargo_embargo. am: 67d93bf01b am: df1ad9100b am: 18ec38355d Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/toml_edit/+/2828111 Change-Id: I67f8adf0b44592e081101568a7ee4c1144f92d5f Signed-off-by: Automerger Merge Worker <[email protected]>
This crate allows you to parse and modify toml documents, while preserving comments, spaces and relative order or items.
toml_edit
is primarily tailored for cargo-edit needs.
use toml_edit::{Document, value}; fn main() { let toml = r#" "hello" = 'toml!' # comment ['a'.b] "#; let mut doc = toml.parse::<Document>().expect("invalid doc"); assert_eq!(doc.to_string(), toml); // let's add a new key/value pair inside a.b: c = {d = "hello"} doc["a"]["b"]["c"]["d"] = value("hello"); // autoformat inline table a.b.c: { d = "hello" } doc["a"]["b"]["c"].as_inline_table_mut().map(|t| t.fmt()); let expected = r#" "hello" = 'toml!' # comment ['a'.b] c = { d = "hello" } "#; assert_eq!(doc.to_string(), expected); }
Things it does not preserve:
Licensed under either of
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.