commit | ef5ec9950fcb3879c975ece51135133da2d9b563 | [log] [tgz] |
---|---|---|
author | Android Build Coastguard Worker <[email protected]> | Thu Aug 08 01:16:33 2024 +0000 |
committer | Android Build Coastguard Worker <[email protected]> | Thu Aug 08 01:16:33 2024 +0000 |
tree | 2db7d45935e84ffa78e7331ee3f7ed6c1c50eff6 | |
parent | d2bdcdc8596313b5ae3c6b693f2f9c74be500ea8 [diff] | |
parent | 41d7a9594ca8a0af6392745d69f9df1596fe2e2d [diff] |
Snap for 12199801 from 41d7a9594ca8a0af6392745d69f9df1596fe2e2d to 25D4-release Change-Id: I42e888196ee83a4da7b53df271d84ddd982eb4ee
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.