Backport changes from publish crates (#1739)

Backport of changes for the published new versions of pep440_rs and
pep508_rs to make it easier to keep them in sync.
This commit is contained in:
konsti 2024-02-20 19:33:27 +01:00 committed by GitHub
parent 8480842d3e
commit 2928c6e574
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 121 additions and 120 deletions

View file

@ -1,3 +1,4 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Deserializer, Serialize};
use std::fmt;
use std::fmt::{Display, Formatter};
@ -13,7 +14,8 @@ use crate::{validate_and_normalize_owned, validate_and_normalize_ref, InvalidNam
/// See:
/// - <https://peps.python.org/pep-0685/#specification/>
/// - <https://packaging.python.org/en/latest/specifications/name-normalization/>
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize)]
#[cfg_attr(feature = "serde", derive(Serialize))]
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct ExtraName(String);
impl ExtraName {
@ -31,6 +33,7 @@ impl FromStr for ExtraName {
}
}
#[cfg(feature = "serde")]
impl<'de> Deserialize<'de> for ExtraName {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where

View file

@ -90,6 +90,7 @@ fn is_normalized(name: impl AsRef<str>) -> Result<bool, InvalidNameError> {
Ok(true)
}
/// Invalid [`crate::PackageName`] or [`crate::ExtraName`].
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct InvalidNameError(String);

View file

@ -1,6 +1,7 @@
use std::borrow::Cow;
use std::str::FromStr;
#[cfg(feature = "serde")]
use serde::{Deserialize, Deserializer, Serialize};
use crate::{validate_and_normalize_owned, validate_and_normalize_ref, InvalidNameError};
@ -11,21 +12,14 @@ use crate::{validate_and_normalize_owned, validate_and_normalize_ref, InvalidNam
/// down to a single `-`, e.g., `---`, `.`, and `__` all get converted to just `-`.
///
/// See: <https://packaging.python.org/en/latest/specifications/name-normalization/>
#[derive(
Debug,
Clone,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
Serialize,
rkyv::Archive,
rkyv::Deserialize,
rkyv::Serialize,
#[cfg_attr(feature = "serde", derive(Serialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
archive(check_bytes),
archive_attr(derive(Debug))
)]
#[archive(check_bytes)]
#[archive_attr(derive(Debug))]
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct PackageName(String);
impl PackageName {
@ -75,6 +69,7 @@ impl FromStr for PackageName {
}
}
#[cfg(feature = "serde")]
impl<'de> Deserialize<'de> for PackageName {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where