26 releases (12 breaking)

0.13.4 Oct 30, 2024
0.12.0 Oct 13, 2024
0.11.0 May 23, 2024
0.10.0 Feb 19, 2024
0.1.1 May 30, 2021

#153 in Parser implementations

Download history 20368/week @ 2024-08-08 19532/week @ 2024-08-15 21452/week @ 2024-08-22 21652/week @ 2024-08-29 24932/week @ 2024-09-05 21213/week @ 2024-09-12 21280/week @ 2024-09-19 21760/week @ 2024-09-26 20148/week @ 2024-10-03 22038/week @ 2024-10-10 20697/week @ 2024-10-17 19018/week @ 2024-10-24 17508/week @ 2024-10-31 20488/week @ 2024-11-07 21627/week @ 2024-11-14 19160/week @ 2024-11-21

81,980 downloads per month
Used in 8 crates (5 directly)

MIT license

33KB
656 lines

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.

Dependencies

~11MB
~199K SLoC