Url

Struct Url 

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

URL representation.

Implementations§

Source§

impl Url

Source

pub fn scheme(&self) -> &str

Get the URL scheme.

Source

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

Get the auth string (if any).

Source

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

Get the username (if any).

Source

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

Get the password (if any).

Source

pub fn netloc(&self) -> &str

Get the network location.

Source

pub fn host(&self) -> &str

Get the host.

Source

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

Get the port (if explicitly provided).

Source

pub fn path(&self) -> &str

Get the path.

Source

pub fn path_with_query(&self) -> &str

Get the path including the query string.

Source

pub fn path_with_query_and_fragment(&self) -> &str

Get the path including the query string and the fragment.

Source

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

Get the query string (if any).

Source

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

Get the fragment (if any).

Source

pub fn base_url(&self) -> Self

Create a new URL by stripping the path, query, and fragment.

Source

pub fn with_auth(&self, auth: Option<&str>) -> Result<Self, UrlParseError>

Create a new URL with a given authentication string.

The authentication string must be URL-encoded.

Source

pub fn with_credentials( &self, username: &str, password: &str, ) -> Result<Self, UrlParseError>

Create a new URL with a given username and password.

The username and password must be URL-encoded.

Source

pub fn with_netloc(&self, netloc: &str) -> Result<Self, UrlParseError>

Create a new URL with a given network location.

Source

pub fn with_query(&self, query: Option<&str>) -> Result<Self, UrlParseError>

Create a new URL with a given query string.

The query string must be URL-encoded.

Source

pub fn with_fragment( &self, fragment: Option<&str>, ) -> Result<Self, UrlParseError>

Create a new URL with a given fragment.

The fragment must be URL-encoded.

Source

pub fn join(&self, input: &str) -> Result<Self, UrlParseError>

Create a new URL by joining this URL with a given input.

The output will depend on the provided input:

  • If the input is empty, the current URL is returned.
  • If the input starts with //, the input is treated as an absolute URL without a scheme, and the scheme of the current URL is used.
  • If the input starts with /, the input is treated as an absolute path and the path of the current URL is replaced with the input.
  • If the input is an absolute URL, the input is returned as a new URL.
  • Otherwise, the input is treated as a relative path and is appended to the current URL’s path, replacing the rightmost path segment.

Trait Implementations§

Source§

impl AsRef<str> for Url

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Url

Source§

fn clone(&self) -> Url

Returns a duplicate 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 Display for Url

Source§

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

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

impl FromStr for Url

Source§

type Err = UrlParseError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Url, UrlParseError>

Parses a string s to return a value of this type. Read more
Source§

impl IntoUrl for &Url

Source§

fn into_url(self) -> Result<Url, UrlParseError>

Convert the object into URL.
Source§

impl IntoUrl for Url

Source§

fn into_url(self) -> Result<Url, UrlParseError>

Convert the object into URL.
Source§

impl TryFrom<String> for Url

Source§

type Error = UrlParseError

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

fn try_from(s: String) -> Result<Url, UrlParseError>

Performs the conversion.

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