commit | 13736f87661877103522c6ef868a43a5d38467fa | [log] [tgz] |
---|---|---|
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | Sun May 26 07:11:16 2024 +0000 |
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | Sun May 26 07:11:16 2024 +0000 |
tree | 96ecf424e86b5cd3dfe3461f1cfd5c76449035ff | |
parent | 052abd9d6962f781bb155079b636e164c8c04856 [diff] | |
parent | 2627d0de1fbaad03f71f6bc07554ec791faf60d8 [diff] |
Snap for 11878398 from 2627d0de1fbaad03f71f6bc07554ec791faf60d8 to busytown-mac-infra-release Change-Id: Ifc31851467c705089d18ff95ed103cc54e2c2dc8
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.