5 releases (3 breaking)

Uses new Rust 2024

new 0.46.1 Apr 15, 2026
0.46.0 Apr 15, 2026
0.45.0 Apr 14, 2026
0.44.0 Mar 1, 2026
0.43.0 Jan 22, 2026

#2882 in Parser implementations

Download history 6/week @ 2026-01-16 41/week @ 2026-01-23 19/week @ 2026-01-30 1/week @ 2026-02-13 4/week @ 2026-02-20 182/week @ 2026-02-27 118/week @ 2026-03-06 216/week @ 2026-03-13 235/week @ 2026-03-20 294/week @ 2026-03-27 171/week @ 2026-04-03 199/week @ 2026-04-10

960 downloads per month
Used in 14 crates (2 directly)

MIT/Apache

1.5MB
613 lines

facet-cargo-toml

Typed Cargo.toml and Cargo.lock parser using facet.

Features

  • Complete Cargo.toml parsing: All manifest fields supported with proper types
  • Cargo.lock parsing: Full lockfile support with dependency resolution
  • Type-safe: Uses facet's derive macros for automatic parsing and validation
  • Well-tested: Validated against hundreds of real-world Cargo.toml files

Usage

Add this to your Cargo.toml:

[dependencies]
facet-cargo-toml = "0.1"

Parse a Cargo.toml

use facet_cargo_toml::CargoManifest;

let manifest = CargoManifest::from_path("Cargo.toml")?;

if let Some(package) = &manifest.package {
    println!("Package name: {:?}", package.name);
    println!("Version: {:?}", package.version);
}

for (name, dep) in manifest.dependencies.unwrap_or_default() {
    println!("Dependency: {name} = {dep:?}");
}

Parse a Cargo.lock

use facet_cargo_toml::Lockfile;

let lockfile = Lockfile::from_path("Cargo.lock")?;

for package in &lockfile.package {
    println!("Locked package: {} {}", package.name, package.version);
}

API Overview

CargoManifest

Complete typed representation of Cargo.toml including:

  • Package metadata
  • Dependencies (regular, dev, build, target-specific)
  • Workspace configuration
  • Build targets (lib, bin, test, bench, example)
  • Features
  • Profiles
  • Lints
  • Patches

Lockfile

Typed representation of Cargo.lock including:

  • Package list with versions and checksums
  • Dependency resolution
  • Source information (registry, git, path)

Why facet?

This crate uses the facet serialization framework which provides:

  • Derive macros: Automatic parsing from TOML with #[derive(Facet)]
  • Better error messages: Uses miette for beautiful parse error reporting
  • Span information: Track the source location of every parsed value
  • Type safety: Strong typing throughout with enums for variants

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

~10MB
~188K SLoC