API Reference

toml

A TOML parser and serializer for Rust, widely used for Cargo manifests and configuration.

Official Documentation ↗
CompatibilityThis documentation covers version v1.2.0+spec-1.1.0. Check the official docs for the latest API surface.

Installation

cargocargo add toml

Methods

toml decodes TOML text into serde-derived structs and encodes structs back to TOML.

Key Features

  • serde integration for typed config
  • Value type for dynamic access
  • Datetime support per the TOML spec

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

Errors

The official API reference declares the following error types:

  • toml::de::Error (struct(任务给定 URL 为 de/enum.Error.html,但最新文档中已为 struct)) — official text: “pub struct Error { /* private fields */ } Errors that can occur when deserializing a type. impl Error pub fn message(&self) -> &str What went wrong pub fn span(&self) -> Option<Range> The start/end index into the original document where the error occurr” (source: https://docs.rs/toml/latest/toml/de/struct.Error.html, fetched 2026-11-08T16:01:12.9137723+08:00)

API reference evidence

Fetched from official sources on 2026-11-08T16:01:12.9137723+08:00 via WebFetch docs.rs toml 模块页、fn.from_str/fn.to_string、de 模块与 de::Error 页.

  • toml::from_str → signature from https://docs.rs/toml/latest/toml/fn.from_str.html; official text: “pub fn from_str<’de, T>(s: &’de str) -> Result<T, Error> where T: Deserialize<’de>, Available on crate features parse and serde only. Deserializes a string into a type.”
  • toml::to_string → signature from https://docs.rs/toml/latest/toml/fn.to_string.html; official text: “pub fn to_string(value: &T) -> Result<String, Error> where T: Serialize + ?Sized, Available on crate features display and serde only. Serialize the given data structure as a String of TOML.”
  • toml::Value → signature from https://docs.rs/toml/latest/toml/#toml-values; official text: “pub enum Value { String(String), Integer(i64), Float(f64), Boolean(bool), Datetime(Datetime), Array(Array), Table(Table), }”

FAQ

Does it support TOML 1.0?
The 0.8 line targets TOML 1.0 for parsing, including dotted keys and inline tables.
How do I format output nicely?
Use to_string_pretty for multi-line output with readable tables, or to_string for compact output.
How are datetimes handled?
The Value::Datetime variant represents them, and serde maps them to appropriate Rust date types when configured.