mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-29 11:07:59 +00:00
Remove serialize traits from verbatim URL (#5501)
This commit is contained in:
parent
4f3dde34dc
commit
8f16f1b746
3 changed files with 2 additions and 38 deletions
|
|
@ -197,7 +197,7 @@ impl<T: Pep508Url + Display> Display for Requirement<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://github.com/serde-rs/serde/issues/908#issuecomment-298027413>
|
/// <https://github.com/serde-rs/serde/issues/908#issuecomment-298027413>
|
||||||
impl<'de, T: Pep508Url + Deserialize<'de>> Deserialize<'de> for Requirement<T> {
|
impl<'de, T: Pep508Url> Deserialize<'de> for Requirement<T> {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
|
|
|
||||||
|
|
@ -13,14 +13,10 @@ use uv_fs::{normalize_absolute_path, normalize_url_path};
|
||||||
use crate::Pep508Url;
|
use crate::Pep508Url;
|
||||||
|
|
||||||
/// A wrapper around [`Url`] that preserves the original string.
|
/// A wrapper around [`Url`] that preserves the original string.
|
||||||
#[derive(Debug, Clone, Eq, derivative::Derivative, serde::Deserialize, serde::Serialize)]
|
#[derive(Debug, Clone, Eq, derivative::Derivative)]
|
||||||
#[derivative(PartialEq, Hash, Ord)]
|
#[derivative(PartialEq, Hash, Ord)]
|
||||||
pub struct VerbatimUrl {
|
pub struct VerbatimUrl {
|
||||||
/// The parsed URL.
|
/// The parsed URL.
|
||||||
#[serde(
|
|
||||||
serialize_with = "Url::serialize_internal",
|
|
||||||
deserialize_with = "Url::deserialize_internal"
|
|
||||||
)]
|
|
||||||
url: Url,
|
url: Url,
|
||||||
/// The URL as it was provided by the user.
|
/// The URL as it was provided by the user.
|
||||||
#[derivative(PartialEq = "ignore")]
|
#[derivative(PartialEq = "ignore")]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
use std::fmt::{Display, Formatter};
|
use std::fmt::{Display, Formatter};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use url::{ParseError, Url};
|
use url::{ParseError, Url};
|
||||||
|
|
||||||
|
|
@ -138,37 +137,6 @@ impl Display for VerbatimParsedUrl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<VerbatimUrl> for VerbatimParsedUrl {
|
|
||||||
type Error = ParsedUrlError;
|
|
||||||
|
|
||||||
fn try_from(verbatim_url: VerbatimUrl) -> Result<Self, Self::Error> {
|
|
||||||
let parsed_url = ParsedUrl::try_from(verbatim_url.to_url())?;
|
|
||||||
Ok(Self {
|
|
||||||
parsed_url,
|
|
||||||
verbatim: verbatim_url,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl serde::ser::Serialize for VerbatimParsedUrl {
|
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
||||||
where
|
|
||||||
S: serde::ser::Serializer,
|
|
||||||
{
|
|
||||||
self.verbatim.serialize(serializer)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'de> serde::de::Deserialize<'de> for VerbatimParsedUrl {
|
|
||||||
fn deserialize<D>(deserializer: D) -> Result<VerbatimParsedUrl, D::Error>
|
|
||||||
where
|
|
||||||
D: serde::de::Deserializer<'de>,
|
|
||||||
{
|
|
||||||
let verbatim_url = VerbatimUrl::deserialize(deserializer)?;
|
|
||||||
Self::try_from(verbatim_url).map_err(serde::de::Error::custom)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// We support three types of URLs for distributions:
|
/// We support three types of URLs for distributions:
|
||||||
/// * The path to a file or directory (`file://`)
|
/// * The path to a file or directory (`file://`)
|
||||||
/// * A Git repository (`git+https://` or `git+ssh://`), optionally with a subdirectory and/or
|
/// * A Git repository (`git+https://` or `git+ssh://`), optionally with a subdirectory and/or
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue