Struct gix::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<Url, 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) -> Url

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<Url, 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<(), Error>

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<Url, 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<(), Error>

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

impl Default for Url

source§

fn default() -> Url

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

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

source§

fn deserialize<__D>( __deserializer: __D ) -> Result<Url, <__D as Deserializer<'de>>::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<(), Error>

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

impl Hash for Url

source§

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

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 + PartialOrd,

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

impl PartialEq for Url

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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

This method 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

This method 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

This method 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

This method 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 as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

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

impl TryFrom<&BStr> for Url

§

type Error = Error

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

fn try_from(value: &BStr) -> Result<Url, <Url as TryFrom<&BStr>>::Error>

Performs the conversion.
source§

impl TryFrom<&OsStr> for Url

§

type Error = Error

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

fn try_from(value: &OsStr) -> Result<Url, <Url as TryFrom<&OsStr>>::Error>

Performs the conversion.
source§

impl TryFrom<&Path> for Url

§

type Error = Error

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

fn try_from(value: &Path) -> Result<Url, <Url as TryFrom<&Path>>::Error>

Performs the conversion.
source§

impl TryFrom<&str> for Url

§

type Error = Error

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

fn try_from(value: &str) -> Result<Url, <Url as TryFrom<&str>>::Error>

Performs the conversion.
source§

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

§

type Error = Error

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

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

Performs the conversion.
source§

impl TryFrom<PathBuf> for Url

§

type Error = Error

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

fn try_from(value: PathBuf) -> Result<Url, <Url as TryFrom<PathBuf>>::Error>

Performs the conversion.
source§

impl TryFrom<String> for Url

§

type Error = Error

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

fn try_from(value: String) -> Result<Url, <Url as TryFrom<String>>::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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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>,

§

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>,