README.md
1# toml_edit
2
3[](https://github.com/toml-rs/toml/actions)
4[](https://codecov.io/gh/toml-rs/toml)
5[](https://crates.io/crates/toml_edit)
6[](https://docs.rs/toml_edit)
7[](https://gitter.im/toml_edit/Lobby)
8
9
10This crate allows you to parse and modify toml
11documents, while preserving comments, spaces *and
12relative order* of items.
13
14`toml_edit` is primarily tailored for [cargo-edit](https://github.com/killercup/cargo-edit/) needs.
15
16## Example
17
18```rust
19use toml_edit::{Document, value};
20
21fn main() {
22 let toml = r#"
23"hello" = 'toml!' # comment
24['a'.b]
25 "#;
26 let mut doc = toml.parse::<Document>().expect("invalid doc");
27 assert_eq!(doc.to_string(), toml);
28 // let's add a new key/value pair inside a.b: c = {d = "hello"}
29 doc["a"]["b"]["c"]["d"] = value("hello");
30 // autoformat inline table a.b.c: { d = "hello" }
31 doc["a"]["b"]["c"].as_inline_table_mut().map(|t| t.fmt());
32 let expected = r#"
33"hello" = 'toml!' # comment
34['a'.b]
35c = { d = "hello" }
36 "#;
37 assert_eq!(doc.to_string(), expected);
38}
39```
40
41## Limitations
42
43Things it does not preserve:
44
45* Order of dotted keys, see [issue](https://github.com/toml-rs/toml/issues/163).
46
47## License
48
49Licensed under either of
50
51- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://apache.org/licenses/LICENSE-2.0)
52- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
53
54### Contribution
55
56Unless 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.
57