mirror of https://github.com/astral-sh/uv
refactored IndexUrl (#15613)
This commit is contained in:
parent
7adc065612
commit
9be016f3f8
|
|
@ -82,22 +82,21 @@ impl schemars::JsonSchema for IndexUrl {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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.
|
/// Return the raw URL for the index.
|
||||||
pub fn url(&self) -> &DisplaySafeUrl {
|
pub fn url(&self) -> &DisplaySafeUrl {
|
||||||
match self {
|
self.inner().raw()
|
||||||
Self::Pypi(url) => url.raw(),
|
|
||||||
Self::Url(url) => url.raw(),
|
|
||||||
Self::Path(url) => url.raw(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert the index URL into a [`DisplaySafeUrl`].
|
/// Convert the index URL into a [`DisplaySafeUrl`].
|
||||||
pub fn into_url(self) -> DisplaySafeUrl {
|
pub fn into_url(self) -> DisplaySafeUrl {
|
||||||
match self {
|
self.inner().to_url()
|
||||||
Self::Pypi(url) => url.to_url(),
|
|
||||||
Self::Url(url) => url.to_url(),
|
|
||||||
Self::Path(url) => url.to_url(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the redacted URL for the index, omitting any sensitive credentials.
|
/// Return the redacted URL for the index, omitting any sensitive credentials.
|
||||||
|
|
@ -140,21 +139,13 @@ impl IndexUrl {
|
||||||
|
|
||||||
impl Display for IndexUrl {
|
impl Display for IndexUrl {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
Display::fmt(self.inner(), f)
|
||||||
Self::Pypi(url) => Display::fmt(url, f),
|
|
||||||
Self::Url(url) => Display::fmt(url, f),
|
|
||||||
Self::Path(url) => Display::fmt(url, f),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Verbatim for IndexUrl {
|
impl Verbatim for IndexUrl {
|
||||||
fn verbatim(&self) -> Cow<'_, str> {
|
fn verbatim(&self) -> Cow<'_, str> {
|
||||||
match self {
|
self.inner().verbatim()
|
||||||
Self::Pypi(url) => url.verbatim(),
|
|
||||||
Self::Url(url) => url.verbatim(),
|
|
||||||
Self::Path(url) => url.verbatim(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -204,11 +195,7 @@ impl serde::ser::Serialize for IndexUrl {
|
||||||
where
|
where
|
||||||
S: serde::ser::Serializer,
|
S: serde::ser::Serializer,
|
||||||
{
|
{
|
||||||
match self {
|
self.inner().without_credentials().serialize(serializer)
|
||||||
Self::Pypi(url) => url.without_credentials().serialize(serializer),
|
|
||||||
Self::Url(url) => url.without_credentials().serialize(serializer),
|
|
||||||
Self::Path(url) => url.without_credentials().serialize(serializer),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -249,11 +236,7 @@ impl From<VerbatimUrl> for IndexUrl {
|
||||||
|
|
||||||
impl From<IndexUrl> for DisplaySafeUrl {
|
impl From<IndexUrl> for DisplaySafeUrl {
|
||||||
fn from(index: IndexUrl) -> Self {
|
fn from(index: IndexUrl) -> Self {
|
||||||
match index {
|
index.inner().to_url()
|
||||||
IndexUrl::Pypi(url) => url.to_url(),
|
|
||||||
IndexUrl::Url(url) => url.to_url(),
|
|
||||||
IndexUrl::Path(url) => url.to_url(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -261,11 +244,7 @@ impl Deref for IndexUrl {
|
||||||
type Target = Url;
|
type Target = Url;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
match self {
|
self.inner()
|
||||||
Self::Pypi(url) => url,
|
|
||||||
Self::Url(url) => url,
|
|
||||||
Self::Path(url) => url,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue