commit | 80e47ae4f88e6eeafa1810f29f0c3326e41bcd21 | [log] [tgz] |
---|---|---|
author | James Farrell <[email protected]> | Wed Aug 07 18:26:32 2024 +0000 |
committer | James Farrell <[email protected]> | Wed Aug 07 18:26:32 2024 +0000 |
tree | 00f1d81e0d171d1229ab4e9382824452b1caac11 | |
parent | 4817100c34c56ceb9ec5810cf892d19179349ba4 [diff] |
Create patch from LICENSE file Test: ran cargo_embargo Bug: 339424309 Change-Id: I1b2f0037f845ac2344504b31b7f558cf08a3f9a4
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.