Skip to main content

RepositoryUrl

Struct RepositoryUrl 

Source
pub struct RepositoryUrl { /* private fields */ }
Expand description

Like CanonicalUrl, but attempts to represent an underlying source repository, abstracting away details like the specific commit or branch, or the subdirectory to build within the repository.

For example, https://github.com/pypa/package.git#subdirectory=pkg_a and https://github.com/pypa/package.git#subdirectory=pkg_b would map to different CanonicalUrl values, but the same RepositoryUrl, since they map to the same resource.

The additional information it holds should only be used to discriminate between sources that hold the exact same commit in their canonical representation, but may differ in the contents such as when Git LFS is enabled.

A different cache key will be computed when Git LFS is enabled. When Git LFS is false or None, the cache key remains unchanged.

Implementations§

Source§

impl RepositoryUrl

Source

pub fn new(url: SafeUrl) -> Self

Source

pub fn parse(url: &str) -> Result<Self, SafeUrlError>

Source

pub fn with_lfs(self, lfs: Option<bool>) -> Self

Methods from Deref<Target = SafeUrl>§

Source

pub fn as_url(&self) -> &SafeUrl

Borrow the URL with the default Unserializable policy.

Source

pub fn as_str(&self) -> &str

Return the complete URL string, including credentials.

Source

pub fn scheme(&self) -> &str

Return the scheme, without the trailing colon.

Source

pub fn authority(&self) -> &str

Return the authority, including any credentials and port.

Source

pub fn cannot_be_a_base(&self) -> bool

Return whether the URL has an opaque path instead of path segments.

Source

pub fn username(&self) -> &str

Return the percent-encoded username.

Source

pub fn password(&self) -> Option<&str>

Return the percent-encoded password, if present.

Source

pub fn has_host(&self) -> bool

Return whether the URL has a host.

Source

pub fn host_str(&self) -> Option<&str>

Return the host as a string, if present.

Source

pub fn host(&self) -> Option<Host<&str>>

Return the parsed host, if present.

Source

pub fn port(&self) -> Option<u16>

Return the explicit non-default port, if present.

Source

pub fn port_or_known_default(&self) -> Option<u16>

Return the explicit port or the scheme’s known default.

Source

pub fn path(&self) -> &str

Return the percent-encoded path.

Source

pub fn path_segments(&self) -> Option<Split<'_, char>>

Return the percent-encoded path segments, unless the path is opaque.

Source

pub fn query_pairs(&self) -> Parse<'_> ⓘ

Return the decoded query name/value pairs.

Source

pub fn fragment(&self) -> Option<&str>

Return the fragment, without the leading hash, if present.

Source

pub fn to_file_path(&self) -> Result<PathBuf, ()>

Convert a file URL to a filesystem path.

Source

pub fn join(&self, input: &str) -> Result<SafeUrl<P>, SafeUrlError>

Parse a string as an URL, with this URL as the base URL.

Source

pub fn without_credentials(&self) -> Cow<'_, SafeUrl<P>>

Return the URL with sensitive userinfo removed, retaining its serialization policy.

The complete query is retained; display and debug formatting redact recognized credentials. Removing userinfo does not make an Unserializable URL serializable:

ⓘ
use uv_redacted::SafeUrl;

let url = SafeUrl::parse("https://user:password@example.com/file.whl")?;
serde_json::to_string(&url.without_credentials())?;
Source

pub fn displayable_with_credentials(&self) -> impl Display

Returns Display implementation that doesn’t mask credentials.

Source

pub fn redact_in(&self, message: &str) -> String

Redact all occurrences of this URL in a message.

This is useful for errors from external tools, which may include the credentialed URL in their command or output instead of using the URL’s Display implementation.

Source

pub fn serialize_internal<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>

Serialize the complete URL using the internal representation of the Url struct.

A field using this serializer must declare the Raw policy:

ⓘ
use uv_redacted::{SafeUrl, policy::Raw};

#[derive(serde::Serialize)]
struct CachedUrl {
    #[serde(serialize_with = "SafeUrl::<Raw>::serialize_internal")]
    url: SafeUrl,
}

serialize_internal method calls require Raw as well:

ⓘ
use uv_redacted::SafeUrl;

let url = SafeUrl::parse("https://user:password@example.com")?;
url.serialize_internal(serde_json::value::Serializer)?;
ⓘ
use uv_redacted::{SafeUrl, policy::Stripped};

let url = SafeUrl::parse("https://user:password@example.com")?
    .with_policy(Stripped);
url.serialize_internal(serde_json::value::Serializer)?;

Trait Implementations§

Source§

impl CacheKey for RepositoryUrl

Source§

fn cache_key(&self, state: &mut CacheKeyHasher)

Source§

fn cache_key_slice(data: &[Self], state: &mut CacheKeyHasher)
where Self: Sized,

Source§

impl Clone for RepositoryUrl

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RepositoryUrl

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for RepositoryUrl

Source§

type Target = SafeUrl

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Display for RepositoryUrl

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for RepositoryUrl

Source§

impl Hash for RepositoryUrl

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for RepositoryUrl

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for RepositoryUrl

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for RepositoryUrl

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for RepositoryUrl

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.