commit | ceb9444e3f706febccabf0dd74c9bd370f7b2c8d | [log] [tgz] |
---|---|---|
author | Andrew Walbran <qwandor@google.com> | Tue Nov 14 14:24:42 2023 +0000 |
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | Tue Nov 14 14:24:42 2023 +0000 |
tree | bc9a93f9b6ee795502937b958fe2a7df6bce38f1 | |
parent | aa09ef692d9ccff9e971822e694ad3cad9a9399e [diff] | |
parent | 64ad77414e7560ca2a04f2c730631a99bff8e866 [diff] |
Migrate to cargo_embargo. am: 67d93bf01b am: 76ddad2e03 am: 64ad77414e Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/toml_edit/+/2828111 Change-Id: I543cd9c87ebbed8dcac8fe1a2b0d0e15b6a3ae14 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
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.