Skip to main content

Url

Struct Url 

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

A parsed URL. Getters and setters are named after the URL interface’s attributes and behave as they do: a setter given a value the spec rejects leaves the URL as it was.

It’s the serialization, in one string, and where each component of it starts. Two URLs are equal, and ordered, by their serializations.

Implementations§

Source§

impl Url

Source

pub fn parse(input: &str) -> Result<Url, ParseError>

Parses an absolute URL, as new URL(input) does.

Source

pub fn parse_with_base(input: &str, base: &Url) -> Result<Url, ParseError>

Parses input against base, as new URL(input, base) does.

Source

pub fn can_parse(input: &str, base: Option<&Url>) -> bool

Whether input parses, against base if there is one: URL.canParse.

Source

pub fn href(&self) -> &str

The whole serialized URL.

Source

pub fn set_href(&mut self, value: &str) -> Result<(), ParseError>

Replaces the whole URL; unlike the other setters, this one fails when the new value doesn’t parse, as the href setter throws.

Source

pub fn origin(&self) -> String

The serialized origin, "null" for an opaque one. A blob: URL’s is its inner URL’s, when that’s http, https or file.

Source

pub fn protocol(&self) -> &str

The scheme with its colon, like "https:".

Source

pub fn set_protocol(&mut self, value: &str)

Source

pub fn username(&self) -> &str

Source

pub fn set_username(&mut self, value: &str)

Source

pub fn password(&self) -> &str

Source

pub fn set_password(&mut self, value: &str)

Source

pub fn host(&self) -> &str

The host and, if there is one, the port.

Source

pub fn set_host(&mut self, value: &str)

Source

pub fn hostname(&self) -> &str

The host without the port.

Source

pub fn set_hostname(&mut self, value: &str)

Source

pub fn port(&self) -> &str

The port, empty when it’s absent or the scheme’s default.

Source

pub fn set_port(&mut self, value: &str)

Source

pub fn pathname(&self) -> &str

Source

pub fn set_pathname(&mut self, value: &str)

Source

pub fn search(&self) -> &str

The query with its ?, or empty when it’s absent or empty.

Source

pub fn hash(&self) -> &str

The fragment with its #, or empty when it’s absent or empty.

Source

pub fn set_hash(&mut self, value: &str)

Source

pub fn search_params(&self) -> SearchParams

The query parsed as application/x-www-form-urlencoded, the list url.searchParams starts from.

Source

pub fn set_search_params(&mut self, params: &SearchParams)

Writes params back as the query, as changing url.searchParams does: an empty list removes the query, ? and all.

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 (const: unstable) · 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 Display for Url

Source§

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

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

impl Eq for Url

Source§

impl FromStr for Url

Source§

type Err = ParseError

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

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

Parses a string s to return a value of this type. 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 (const: unstable) · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

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

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

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Url

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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

Auto Trait Implementations§

§

impl Forget for Url

§

impl Freeze for Url

§

impl Move for Url

§

impl RefUnwindSafe for Url

§

impl Send for Url

§

impl Sync for Url

§

impl Unpin for Url

§

impl UnsafeUnpin 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.