Search

Lib.rs

› Parser implementations › TOML
#toml-parser #encoding #toml

toml_edit

Yet another format-preserving TOML parser

Owned by Ed Page, Andronik, toml-rs.

  • Audit
  • Install
  • API reference
  • GitHub repo (toml-rs)

123 releases

Uses new Rust 2024

0.25.11+spec-1.1.0 Apr 7, 2026
0.25.9+spec-1.1.0 Mar 31, 2026
0.24.0+spec-1.1.0 Dec 18, 2025
0.23.7 Oct 9, 2025
0.1.1 Dec 17, 2017

#94 in Parser implementations

Download history 6700567/week @ 2026-01-19 6894897/week @ 2026-01-26 7398559/week @ 2026-02-02 7478462/week @ 2026-02-09 7245117/week @ 2026-02-16 8292784/week @ 2026-02-23 9424339/week @ 2026-03-02 9813323/week @ 2026-03-09 9276819/week @ 2026-03-16 9149079/week @ 2026-03-23 9174125/week @ 2026-03-30 9168978/week @ 2026-04-06 9743411/week @ 2026-04-13 9896274/week @ 2026-04-20 9978075/week @ 2026-04-27 9542267/week @ 2026-05-04

39,903,660 downloads per month
Used in 19,018 crates (955 directly)

MIT/Apache

425KB
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

  • Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
  • MIT license (LICENSE-MIT or https://opensource.org/license/mit)

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
~54K SLoC

  • debug? anstream
  • debug? anstyle
  • debug? parse toml_parser
  • indexmap+std
  • toml_datetime 1.1
  • parse winnow 1.0
  • display toml_writer
  • serde? serde_core
  • serde? serde_spanned 1.1+serde
  • dev proptest
  • dev serde+derive
  • dev serde-untagged
  • dev serde_json
  • dev snapbox 1.1
  • dev toml-test-data 2.4
  • dev toml-test-harness+snapshot
  • dev walkdir

Other feature

  • unbounded
Related: toml, toml_datetime, toml_parser, toml_writer, toml_write, serde_spanned
See also: whats-changed, ron, tar, compact_str, serde_path_to_error, wit-parser, ciborium, asn1-rs, serde_core, tree-sitter-toml-ng, boml

Lib.rs is an unofficial list of Rust/Cargo crates, created by kornelski. It contains data from multiple sources, including heuristics, and manually curated data. Content of this page is not necessarily endorsed by the authors of the crate. This site is not affiliated with nor endorsed by the Rust Project. Blocks and bans are applied manually. To report or appeal, please file a bug.