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 (see the Display::fmt() implementation).

Deviation

Note that we do not support passing the password using the URL as it’s likely leading to accidents.

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 going to be used in 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, with None unsetting it. Returns 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>

Returns the user mentioned in the url, if present.

source

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

Returns the password mentioned in the url, if present.

source

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

Returns 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 going to be used in a command-line application, call Self::host_argument_safe() instead.

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 if the host is going to be passed to a command-line application.

source

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

Return the path of this URL and 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 if the path is going to be passed to a command-line application.

source

pub fn path_is_root(&self) -> bool

Returns true if the path portion of the url is /.

source

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

Returns 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 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) -> Selfwhere Self: Sized,

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

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

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

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

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

impl PartialEq<Url> 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<Url> 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 StructuralEq for Url

source§

impl StructuralPartialEq for Url

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

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 Twhere 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere 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, U> TryFrom<U> for Twhere 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 Twhere 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 Twhere T: for<'de> Deserialize<'de>,