refactored IndexUrl (#15613)

This commit is contained in:
adamnemecek 2025-09-01 00:28:42 -07:00 committed by GitHub
parent 7adc065612
commit 9be016f3f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 35 deletions

View File

@ -82,22 +82,21 @@ impl schemars::JsonSchema for IndexUrl {
}
impl IndexUrl {
#[inline]
fn inner(&self) -> &VerbatimUrl {
match self {
Self::Pypi(url) | Self::Url(url) | Self::Path(url) => url,
}
}
/// Return the raw URL for the index.
pub fn url(&self) -> &DisplaySafeUrl {
match self {
Self::Pypi(url) => url.raw(),
Self::Url(url) => url.raw(),
Self::Path(url) => url.raw(),
}
self.inner().raw()
}
/// Convert the index URL into a [`DisplaySafeUrl`].
pub fn into_url(self) -> DisplaySafeUrl {
match self {
Self::Pypi(url) => url.to_url(),
Self::Url(url) => url.to_url(),
Self::Path(url) => url.to_url(),
}
self.inner().to_url()
}
/// Return the redacted URL for the index, omitting any sensitive credentials.
@ -140,21 +139,13 @@ impl IndexUrl {
impl Display for IndexUrl {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::Pypi(url) => Display::fmt(url, f),
Self::Url(url) => Display::fmt(url, f),
Self::Path(url) => Display::fmt(url, f),
}
Display::fmt(self.inner(), f)
}
}
impl Verbatim for IndexUrl {
fn verbatim(&self) -> Cow<'_, str> {
match self {
Self::Pypi(url) => url.verbatim(),
Self::Url(url) => url.verbatim(),
Self::Path(url) => url.verbatim(),
}
self.inner().verbatim()
}
}
@ -204,11 +195,7 @@ impl serde::ser::Serialize for IndexUrl {
where
S: serde::ser::Serializer,
{
match self {
Self::Pypi(url) => url.without_credentials().serialize(serializer),
Self::Url(url) => url.without_credentials().serialize(serializer),
Self::Path(url) => url.without_credentials().serialize(serializer),
}
self.inner().without_credentials().serialize(serializer)
}
}
@ -249,11 +236,7 @@ impl From<VerbatimUrl> for IndexUrl {
impl From<IndexUrl> for DisplaySafeUrl {
fn from(index: IndexUrl) -> Self {
match index {
IndexUrl::Pypi(url) => url.to_url(),
IndexUrl::Url(url) => url.to_url(),
IndexUrl::Path(url) => url.to_url(),
}
index.inner().to_url()
}
}
@ -261,11 +244,7 @@ impl Deref for IndexUrl {
type Target = Url;
fn deref(&self) -> &Self::Target {
match self {
Self::Pypi(url) => url,
Self::Url(url) => url,
Self::Path(url) => url,
}
self.inner()
}
}