#toml-parser #encoding #toml

toml_edit

Yet another format-preserving TOML parser

110 releases

0.24.0+spec-1.1.0 Dec 18, 2025
0.23.7 Oct 9, 2025
0.23.2 Jul 18, 2025
0.22.24 Feb 10, 2025
0.1.1 Dec 17, 2017

#73 in Parser implementations

Download history 5536061/week @ 2025-10-19 5755204/week @ 2025-10-26 5657586/week @ 2025-11-02 5407115/week @ 2025-11-09 5718270/week @ 2025-11-16 4888359/week @ 2025-11-23 5531039/week @ 2025-11-30 6025340/week @ 2025-12-07 5920431/week @ 2025-12-14 3454251/week @ 2025-12-21 3350487/week @ 2025-12-28 5944298/week @ 2026-01-04 6574289/week @ 2026-01-11 6685466/week @ 2026-01-18 6832517/week @ 2026-01-25 7364139/week @ 2026-02-01

27,920,919 downloads per month
Used in 16,270 crates (694 directly)

MIT/Apache

415KB
10K SLoC

toml_edit

Documentation License Crates Status

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.

Example

use toml_edit::{DocumentMut, value};

fn main() {
    let toml = r#"
"hello" = 'toml!' # comment
['a'.b]
    "#;
    let mut doc = toml.parse::<DocumentMut>().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);
}

Limitations

Things it does not preserve:

  • Order of dotted keys, see issue.

License

Licensed under either of

at your option.

Contribution

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.

Dependencies

~0.7–3MB
~57K SLoC