commit | 0467683a3df593c53ba618f792b1ad54e861a9f5 | [log] [tgz] |
---|---|---|
author | Treehugger Robot <[email protected]> | Wed Aug 07 22:54:13 2024 +0000 |
committer | Automerger Merge Worker <[email protected]> | Wed Aug 07 22:54:13 2024 +0000 |
tree | 2db7d45935e84ffa78e7331ee3f7ed6c1c50eff6 | |
parent | 2eb4aad497ea33861179136909ff59a7108e6e0b [diff] | |
parent | 0c4446f6e0ea8b766b2c273802bbc3d94924be77 [diff] |
Merge "Create patch from LICENSE file" into main am: 0c4446f6e0 Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/toml_edit/+/3211620 Change-Id: Ie65b627920d27f84f161114d583d58df5ed1c2d0 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 of 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.