Struct git_url::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.

Implementations§

source§

impl Url

Instantiation

source

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

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

source

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

Create a new instance from the given parts, which will be validated by parsing them back from its alternative form.

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

Turn a file url like file://relative into file:///root/relative, hence it assures the url’s path component is absolute.

source§

impl Url

Access

source

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

Returns the user mentioned in the url, if present.

source

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

Returns the host mentioned in the url, if present.

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) -> Result<Self, Error>

Turn a file url like file://relative into file:///root/relative, hence it assures the url’s path component is absolute.

source§

impl Url

Serialization

source

pub fn write_to(&self, out: impl 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 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) -> 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::Ok, __S::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<Self, Self::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<Self, Self::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<Self, Self::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<Self, Self::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<Self, Self::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<Self, Self::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<Self, Self::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,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 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.
const: unstable · 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.
const: unstable · 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>,