pyproject-toml

Crates.iopyproject-toml
lib.rspyproject-toml
version0.13.4
sourcesrc
created_at2021-05-02 14:35:43.270605
updated_at2024-10-30 10:08:13.954113
descriptionpyproject.toml parser in Rust
homepage
repositoryhttps://github.com/PyO3/pyproject-toml-rs.git
max_upload_size
id392210
size36,442
Maintainers (github:pyo3:maintainers)

documentation

README

pyproject-toml-rs

GitHub Actions Crates.io docs.rs

pyproject.toml parser in Rust.

Installation

Add it to your Cargo.toml:

[dependencies]
pyproject-toml = "0.8"

then you are good to go. If you are using Rust 2015 you have to add extern crate pyproject_toml to your crate root as well.

Extended parsing

If you want to add additional fields parsing, you can do it with serde's flatten feature and implement the Deref trait, for example:

use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PyProjectToml {
    #[serde(flatten)]
    inner: pyproject_toml::PyProjectToml,
    tool: Option<Tool>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "kebab-case")]
pub struct Tool {
    maturin: Option<ToolMaturin>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "kebab-case")]
pub struct ToolMaturin {
    sdist_include: Option<Vec<String>>,
}

impl std::ops::Deref for PyProjectToml {
    type Target = pyproject_toml::PyProjectToml;

    fn deref(&self) -> &Self::Target {
        &self.inner
    }
}

impl PyProjectToml {
    pub fn new(content: &str) -> Result<Self, toml::de::Error> {
        toml::from_str(content)
    }
}

License

This work is released under the MIT license. A copy of the license is provided in the LICENSE file.

Commit count: 87

cargo fmt