Expand description
§toml_edit
This crate allows you to parse and modify toml documents, while preserving comments, spaces and relative order of items.
If you also need the ease of a more traditional API, see the toml crate.
§Example
use toml_edit::{DocumentMut, value};
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);§Controlling formatting
By default, values are created with default formatting
let mut doc = toml_edit::DocumentMut::new();
doc["foo"] = toml_edit::value("bar");
let expected = r#"foo = "bar"
"#;
assert_eq!(doc.to_string(), expected);You can choose a custom TOML representation by parsing the value.
let mut doc = toml_edit::DocumentMut::new();
doc["foo"] = "'bar'".parse::<toml_edit::Item>().unwrap();
let expected = r#"foo = 'bar'
"#;
assert_eq!(doc.to_string(), expected);§Limitations
Things it does not preserve:
- Order of dotted keys, see issue.
 
Modules§
- de
 - Deserializing TOML into Rust structures.
 - ser
 - Serializing Rust structures into TOML.
 - visit
 - Document tree traversal to walk a shared borrow of a document tree.
 - visit_
mut  - Document tree traversal to mutate an exclusive borrow of a document tree in place.
 
Structs§
- Array
 - A TOML 
Valuethat contains a sequence ofValues - Array
OfTables  - A top-level sequence of 
Tables, each under their own header - Date
 - A parsed TOML date value
 - Datetime
 - A parsed TOML datetime value
 - Datetime
Parse Error  - Error returned from parsing a 
Datetimein theFromStrimplementation. - Decor
 - A prefix and suffix,
 - Document
Mut  - The editable root TOML 
Table, containingKey/Valuepairs and all other logicTables - Formatted
 - A scalar TOML 
Value’s logical value and its representation in a&str - ImDocument
 - The root TOML 
Table, containingKey/Valuepairs and all other logicTables - Inline
Occupied Entry  - A view into a single occupied location in an 
InlineTable. - Inline
Table  - A TOML 
Valuethat contains a collection ofKey/Valuepairs - Inline
Vacant Entry  - A view into a single empty location in an 
InlineTable. - Internal
String  - Opaque string storage internal to 
toml_edit - Key
 - For Key/
Valuepairs under aTableheader or inside anInlineTable - KeyMut
 - A mutable reference to a 
Key’s formatting - Occupied
Entry  - A view into a single occupied location in a 
Table. - RawString
 - Opaque string storage for raw TOML; internal to 
toml_edit - Repr
 - A TOML 
Valueencoded as a&str - Table
 - A TOML table, a top-level collection of key/
Valuepairs under a header and logical sub-tables - Time
 - A parsed TOML time value
 - Toml
Error  - A TOML parse error
 - Vacant
Entry  - A view into a single empty location in a 
Table. 
Enums§
- Entry
 - A view into a single location in a 
Table, which may be vacant or occupied. - Inline
Entry  - A view into a single location in an 
InlineTable, which may be vacant or occupied. - Item
 - Type representing either a value, a table, an array of tables, or none.
 - Offset
 - A parsed TOML time offset
 - Value
 - For 
Key/Value pairs under aTableheader or inside another Value 
Traits§
- Table
Like  - This trait represents either a 
Table, or anInlineTable. 
Functions§
Type Aliases§
- Array
Into Iter  - An owned iterator type over 
Array’sValues - Array
Iter  - An iterator type over 
Array’sValues - Array
Iter Mut  - An iterator type over 
Array’sValues - Array
OfTables Into Iter  - An iterator type over 
ArrayOfTables’sTables - Array
OfTables Iter  - An iterator type over 
ArrayOfTables’sTables - Array
OfTables Iter Mut  - An iterator type over 
ArrayOfTables’sTables - Document
Deprecated  - Deprecated, replaced with 
DocumentMut - Inline
Table Into Iter  - An owned iterator type over an 
InlineTable’sKey/Valuepairs - Inline
Table Iter  - An iterator type over 
InlineTable’sKey/Valuepairs - Inline
Table Iter Mut  - A mutable iterator type over 
InlineTable’sKey/Valuepairs - Into
Iter  - An owned iterator type over 
Table’sKey/Itempairs - Iter
 - An iterator type over 
Table’sKey/Itempairs - IterMut
 - A mutable iterator type over 
Table’sKey/Itempairs