#toml-parser #encoding #toml

toml_edit

Yet another format-preserving TOML parser

113 releases

new 0.25.1+spec-1.1.0 Feb 12, 2026
0.24.1+spec-1.1.0 Feb 10, 2026
0.24.0+spec-1.1.0 Dec 18, 2025
0.23.7 Oct 9, 2025
0.1.1 Dec 17, 2017

#75 in Parser implementations

Download history 5768764/week @ 2025-10-24 5535404/week @ 2025-10-31 5517621/week @ 2025-11-07 5650950/week @ 2025-11-14 5326626/week @ 2025-11-21 5133366/week @ 2025-11-28 5996711/week @ 2025-12-05 5916716/week @ 2025-12-12 4091883/week @ 2025-12-19 3180651/week @ 2025-12-26 5383120/week @ 2026-01-02 6497145/week @ 2026-01-09 6628714/week @ 2026-01-16 6823956/week @ 2026-01-23 7205150/week @ 2026-01-30 7457727/week @ 2026-02-06

29,301,592 downloads per month
Used in 16,389 crates (708 directly)

MIT/Apache

420KB
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.6–3MB
~57K SLoC