gix_url

Struct Url

Source
pub struct Url {
    pub scheme: Scheme,
    pub port: Option<u16>,
    pub path: BString,
    /* private fields */
}
Expand description

A URL with support for specialized git related capabilities.

Additionally there is support for deserialization and serialization.

§Security Warning

URLs may contain passwords and using standard formatting will redact such password, whereas lossless serialization will contain all parts of the URL. Beware that some URls still print secrets if they use them outside of the designated password fields.

Also note that URLs that fail to parse are typically stored in the resulting error type and printed in full using its display implementation.

Fields§

§scheme: Scheme

The URL scheme.

§port: Option<u16>

The port to use when connecting to a host. If None, standard ports depending on scheme will be used.

§path: BString

The path portion of the URL, usually the location of the git repository.

§Security Warning

URLs allow paths to start with - which makes it possible to mask command-line arguments as path which then leads to the invocation of programs from an attacker controlled URL. See https://secure.phabricator.com/T12961 for details.

If this value is ever going to be passed to a command-line application, call Self::path_argument_safe() instead.

Implementations§

Source§

impl Url

Instantiation

Source

pub fn from_parts( scheme: Scheme, user: Option<String>, password: Option<String>, host: Option<String>, port: Option<u16>, path: BString, serialize_alternative_form: bool, ) -> Result<Self, Error>

Create a new instance from the given parts, including a password, which will be validated by parsing them back.

Source§

impl Url

Modification

Source

pub fn set_user(&mut self, user: Option<String>) -> Option<String>

Set the given user, or unset it with None. Return the previous value.

Source

pub fn set_password(&mut self, password: Option<String>) -> Option<String>

Set the given password, or unset it with None. Return the previous value.

Source§

impl Url

Builder

Source

pub fn serialize_alternate_form(self, use_alternate_form: bool) -> Self

Enable alternate serialization for this url, e.g. file:///path becomes /path.

This is automatically set correctly for parsed URLs, but can be set here for urls created by constructor.

Source

pub fn canonicalize(&mut self, current_dir: &Path) -> Result<(), Error>

Turn a file url like file://relative into file:///root/relative, hence it assures the url’s path component is absolute, using current_dir if needed to achieve that.

Source§

impl Url

Access

Source

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

Return the username mentioned in the URL, if present.

§Security Warning

URLs allow usernames to start with - which makes it possible to mask command-line arguments as username which then leads to the invocation of programs from an attacker controlled URL. See https://secure.phabricator.com/T12961 for details.

If this value is ever going to be passed to a command-line application, call Self::user_argument_safe() instead.

Source

pub fn user_as_argument(&self) -> ArgumentSafety<'_>

Classify the username of this URL by whether it is safe to pass as a command-line argument.

Use this method instead of Self::user() if the host is going to be passed to a command-line application. If the unsafe and absent cases need not be distinguished, Self::user_argument_safe() may also be used.

Source

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

Return the username of this URL if present and if it can’t be mistaken for a command-line argument.

Use this method or Self::user_as_argument() instead of Self::user() if the host is going to be passed to a command-line application. Prefer Self::user_as_argument() unless the unsafe and absent cases need not be distinguished from each other.

Source

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

Return the password mentioned in the url, if present.

Source

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

Return the host mentioned in the URL, if present.

§Security Warning

URLs allow hosts to start with - which makes it possible to mask command-line arguments as host which then leads to the invocation of programs from an attacker controlled URL. See https://secure.phabricator.com/T12961 for details.

If this value is ever going to be passed to a command-line application, call Self::host_as_argument() or Self::host_argument_safe() instead.

Source

pub fn host_as_argument(&self) -> ArgumentSafety<'_>

Classify the host of this URL by whether it is safe to pass as a command-line argument.

Use this method instead of Self::host() if the host is going to be passed to a command-line application. If the unsafe and absent cases need not be distinguished, Self::host_argument_safe() may also be used.

Source

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

Return the host of this URL if present and if it can’t be mistaken for a command-line argument.

Use this method or Self::host_as_argument() instead of Self::host() if the host is going to be passed to a command-line application. Prefer Self::host_as_argument() unless the unsafe and absent cases need not be distinguished from each other.

Source

pub fn path_argument_safe(&self) -> Option<&BStr>

Return the path of this URL if it can’t be mistaken for a command-line argument. Note that it always begins with a slash, which is ignored for this comparison.

Use this method instead of accessing Self::path directly if the path is going to be passed to a command-line application, unless it is certain that the leading / will always be included.

Source

pub fn path_is_root(&self) -> bool

Return true if the path portion of the URL is /.

Source

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

Return the actual or default port for use according to the URL scheme. Note that there may be no default port either.

Source§

impl Url

Transformation

Source

pub fn canonicalized(&self, current_dir: &Path) -> Result<Self, Error>

Turn a file URL like file://relative into file:///root/relative, hence it assures the URL’s path component is absolute, using current_dir if necessary.

Source§

impl Url

Serialization

Source

pub fn write_to(&self, out: &mut dyn Write) -> Result<()>

Write this URL losslessly to out, ready to be parsed again.

Source

pub fn to_bstring(&self) -> BString

Transform ourselves into a binary string, losslessly, or fail if the URL is malformed due to host or user parts being incorrect.

Source§

impl Url

Deserialization

Source

pub fn from_bytes(bytes: &BStr) -> Result<Self, Error>

Parse a URL from bytes.

Trait Implementations§

Source§

impl Clone for Url

Source§

fn clone(&self) -> Url

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Url

Source§

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

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

impl Default for Url

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Url

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Url

Source§

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

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

impl Hash for Url

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 Url

Source§

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

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

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

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

impl PartialEq for Url

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Url

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · 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 · 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 · 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 · 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 Serialize for Url

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<&BStr> for Url

Source§

type Error = Error

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

fn try_from(value: &BStr) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&OsStr> for Url

Source§

type Error = Error

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

fn try_from(value: &OsStr) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&Path> for Url

Source§

type Error = Error

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

fn try_from(value: &Path) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&str> for Url

Source§

type Error = Error

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

fn try_from(value: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> TryFrom<Cow<'a, BStr>> for Url

Source§

type Error = Error

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

fn try_from(value: Cow<'a, BStr>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<PathBuf> for Url

Source§

type Error = Error

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

fn try_from(value: PathBuf) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<String> for Url

Source§

type Error = Error

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

fn try_from(value: String) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for Url

Source§

impl StructuralPartialEq for Url

Auto Trait Implementations§

§

impl Freeze for Url

§

impl RefUnwindSafe for Url

§

impl Send for Url

§

impl Sync for Url

§

impl Unpin for Url

§

impl UnwindSafe for Url

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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<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§

default 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T