commit | 4ab9b21e71535a62def8aefea49049654328afd4 | [log] [tgz] |
---|---|---|
author | Android Build Coastguard Worker <[email protected]> | Thu May 23 23:15:33 2024 +0000 |
committer | Android Build Coastguard Worker <[email protected]> | Thu May 23 23:15:33 2024 +0000 |
tree | 96ecf424e86b5cd3dfe3461f1cfd5c76449035ff | |
parent | 6233702964f4c8ffeadad89ceb691d934fc798c0 [diff] | |
parent | 0fc72f34a6dbd1e10a2791bf57550917a9a043fa [diff] |
Snap for 11881322 from 0fc72f34a6dbd1e10a2791bf57550917a9a043fa to 24Q3-release Change-Id: I787de43a0e7b31abefe565d21f75ef16922b04eb
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.