5 unstable releases

0.3.1 Nov 18, 2021
0.3.0 Nov 17, 2021
0.2.0 Aug 13, 2021
0.1.1 May 30, 2021
0.1.0 May 2, 2021

#347 in Parser implementations

Download history 872/week @ 2021-08-11 392/week @ 2021-08-18 516/week @ 2021-08-25 914/week @ 2021-09-01 396/week @ 2021-09-08 1038/week @ 2021-09-15 697/week @ 2021-09-22 391/week @ 2021-09-29 744/week @ 2021-10-06 980/week @ 2021-10-13 345/week @ 2021-10-20 505/week @ 2021-10-27 664/week @ 2021-11-03 765/week @ 2021-11-10 1058/week @ 2021-11-17 1332/week @ 2021-11-24

4,001 downloads per month
Used in maturin

MIT license

10KB
154 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.3"

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

~0.7–1.4MB
~33K SLoC