uv_pypi_types/metadata/
metadata10.rs

1use serde::Deserialize;
2
3use uv_normalize::PackageName;
4
5use crate::MetadataError;
6use crate::metadata::Headers;
7
8/// A subset of the full core metadata specification, including only the
9/// fields that have been consistent across all versions of the specification.
10///
11/// Core Metadata 1.0 is specified in <https://peps.python.org/pep-0241/>.
12#[derive(Deserialize, Debug, Clone)]
13#[serde(rename_all = "kebab-case")]
14pub struct Metadata10 {
15    pub name: PackageName,
16    pub version: String,
17}
18
19impl Metadata10 {
20    /// Parse the [`Metadata10`] from a `PKG-INFO` file, as included in a source distribution.
21    pub fn parse_pkg_info(content: &[u8]) -> Result<Self, MetadataError> {
22        let headers = Headers::parse(content)?;
23        let name = PackageName::from_owned(
24            headers
25                .get_first_value("Name")
26                .ok_or(MetadataError::FieldNotFound("Name"))?,
27        )?;
28        let version = headers
29            .get_first_value("Version")
30            .ok_or(MetadataError::FieldNotFound("Version"))?;
31        Ok(Self { name, version })
32    }
33}