https://github.com/pyo3/pyproject-toml-rs
pyproject.toml parser in Rust
https://github.com/pyo3/pyproject-toml-rs
Last synced: 9 months ago
JSON representation
pyproject.toml parser in Rust
- Host: GitHub
- URL: https://github.com/pyo3/pyproject-toml-rs
- Owner: PyO3
- License: mit
- Created: 2021-05-02T14:03:57.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-10-24T09:20:13.000Z (about 1 year ago)
- Last Synced: 2024-10-25T05:27:29.675Z (about 1 year ago)
- Language: Rust
- Size: 94.7 KB
- Stars: 24
- Watchers: 12
- Forks: 9
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: Changelog.md
- License: LICENSE
Awesome Lists containing this project
README
# pyproject-toml-rs
[](https://github.com/PyO3/pyproject-toml-rs/actions?query=workflow%3ACI)
[](https://crates.io/crates/pyproject-toml)
[](https://docs.rs/pyproject-toml/)
`pyproject.toml` parser in Rust.
## Installation
Add it to your ``Cargo.toml``:
```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`](https://github.com/serde-rs/serde)'s
[`flatten`](https://serde.rs/field-attrs.html#flatten) feature and implement the [`Deref`](https://doc.rust-lang.org/std/ops/trait.Deref.html) trait,
for example:
```rust
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PyProjectToml {
#[serde(flatten)]
inner: pyproject_toml::PyProjectToml,
tool: Option,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "kebab-case")]
pub struct Tool {
maturin: Option,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "kebab-case")]
pub struct ToolMaturin {
sdist_include: Option>,
}
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 {
toml::from_str(content)
}
}
```
## License
This work is released under the MIT license. A copy of the license is provided in the [LICENSE](./LICENSE) file.