mirror of https://github.com/astral-sh/uv
Serde support for WheelFilename through str repr (#459)
I need this later, splitting out for PR size
This commit is contained in:
parent
3df3110800
commit
255edf4445
|
|
@ -864,6 +864,7 @@ dependencies = [
|
|||
"pep440_rs 0.3.12",
|
||||
"platform-tags",
|
||||
"puffin-normalize",
|
||||
"serde",
|
||||
"thiserror",
|
||||
"url",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ pep440_rs = { path = "../pep440-rs" }
|
|||
platform-tags = { path = "../platform-tags" }
|
||||
puffin-normalize = { path = "../puffin-normalize" }
|
||||
|
||||
serde = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
url = { workspace = true }
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::str::FromStr;
|
||||
|
||||
|
|
@ -8,7 +9,7 @@ use pep440_rs::Version;
|
|||
use platform_tags::{TagPriority, Tags};
|
||||
use puffin_normalize::{InvalidNameError, PackageName};
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
|
||||
pub struct WheelFilename {
|
||||
pub name: PackageName,
|
||||
pub version: Version,
|
||||
|
|
@ -167,6 +168,25 @@ impl TryFrom<&Url> for WheelFilename {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for WheelFilename {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let s = String::deserialize(deserializer)?;
|
||||
FromStr::from_str(&s).map_err(de::Error::custom)
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for WheelFilename {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str(&self.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum WheelFilenameError {
|
||||
#[error("The wheel filename \"{0}\" is invalid: {1}")]
|
||||
|
|
|
|||
Loading…
Reference in New Issue