TOML Schema proposal, with Cargo.toml as an example

โš“ Rust    ๐Ÿ“… 2026-05-25    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 2      

surdeus

Hi Rust community,

Iโ€™ve been working on a small project since 2020 called TOML Schema, a schema language for validating TOML documents:

Since Rust and Cargo are one of the most visible and successful users of TOML, I thought this community might be interested in the idea.

The project defines a .tosd schema format, itself written in TOML, for describing the expected shape of TOML documents: tables, arrays, primitive types, reusable definitions, optional fields, collections, alternatives via oneof / anyof, and so on.

As an experiment, I drafted a Cargo.tosd schema that models the documented structure of Cargo.toml manifests:

Cargo.tosd

The goal is not to replace Cargoโ€™s own manifest parser or semantic validation. For example, this schema does not attempt to enforce every cross-field Cargo rule. Instead, it focuses on the document shape: package metadata, dependency forms, targets, features, profiles, patches, workspaces, lints, and related sections.

A simple example from the schema is Cargo dependencies, which can be either a version string or an inline/table dependency definition:

 [types.dependency]
 oneof = [ "types.stringValue", "types.dependencyTable" ]
 
 [types.dependencyCollection]
 type = "collection"
 typeof = "types.dependency"

This allows forms such as:

 serde = "1"
 regex = { version = "1", features = ["perf"] }

Iโ€™d be interested in feedback from Rust/Cargo users and maintainers:

  • Does this kind of TOML schema language seem useful for the broader TOML ecosystem?
  • Are there Cargo manifest shapes this example is missing?
  • Would a schema like this be useful for editor tooling, documentation, validation, or manifest generation?
  • Are there design choices that feel awkward from a Rust/Cargo perspective ?

The project currently includes reference implementations, including a Rust one, and the Cargo schema example validates against the TOML Schema self-schema.

Note: the project started in 2020 when the bulk of the vocabulary and schema design was set. The reference implementations (Rust, Go, and Java) were generated with agents in the past few days.

Thanks for taking a look.

1 post - 1 participant

Read full topic

๐Ÿท๏ธ Rust_feed