#cargo-toml #toml-parser #semver #validation #version #fields #author

workspacer-toml

A utility crate for parsing, validating, and handling Cargo.toml files as part of the Workspacer ecosystem

5 releases (breaking)

0.5.0 Feb 21, 2025
0.4.0 Feb 21, 2025
0.3.0 Feb 17, 2025
0.2.0 Feb 17, 2025
0.1.0 Feb 9, 2025

#55 in #toml-parser

Download history 119/week @ 2025-02-05 209/week @ 2025-02-12 307/week @ 2025-02-19 21/week @ 2025-02-26

656 downloads per month
Used in 4 crates (2 directly)

MIT/Apache

135KB
2K SLoC

workspacer-toml

workspacer-toml is a utility crate within the Workspacer ecosystem that provides functionality for parsing, validating, and manipulating Cargo.toml files. It offers a convenient handle (CargoToml) to access and verify a crate’s manifest, ensuring that required fields exist and that the version string is a valid SemVer.

Features

  • TOML Parsing and Validation:
    Reads and parses a Cargo.toml file into a toml::Value and validates its contents.

  • Required Field Checks:
    Ensures that the [package] section contains all required fields for both integrity (e.g. name, version) and publishing (e.g. authors, license).

  • Version Validation:
    Uses the semver crate to verify that the version string follows valid SemVer conventions.

  • Ready-for-Publishing Checks:
    Implements the ReadyForCargoPublish trait to determine if a crate is properly configured for Cargo publishing.

  • Unified Error Handling:
    Provides a comprehensive set of error types (via error_tree!) for issues encountered during TOML reading, parsing, or validation.

Installation

Add the following dependency to your Cargo.toml:

[dependencies]
workspacer-toml = "0.1.0"

Usage

Below is a simple example of how to use workspacer-toml to create a CargoToml handle and validate a Cargo.toml file:

use workspacer_toml::{CargoToml, CargoTomlInterface};
use workspacer_interface::ReadyForCargoPublish;
use tokio;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Provide the path to a Cargo.toml file.
    let cargo_toml_path = "path/to/Cargo.toml";
    
    // Create a CargoToml handle from the file.
    let cargo_toml = CargoToml::new(cargo_toml_path).await?;
    
    // Validate the integrity of the Cargo.toml file.
    cargo_toml.validate_integrity()?;
    
    // Check if the Cargo.toml is ready for publishing.
    cargo_toml.ready_for_cargo_publish().await?;
    
    println!("Cargo.toml is valid and ready for publishing.");
    Ok(())
}

Contributing

Contributions are welcome! Please see the repository for guidelines on contributing and reporting issues.

License

This project is dual-licensed under either the MIT license or the Apache License, Version 2.0, at your option.

Dependencies

~25–41MB
~654K SLoC