Skip to main content

Url

Struct Url 

Source
pub struct Url<'a> { /* private fields */ }
Expand description

A parsed URL record backed by its WHATWG serialization (href).

Component boundaries are u32 byte offsets into Self::as_str. Absent optional markers use the sentinel Url::NONE (u32::MAX).

When the input is already in canonical form, Backing::Borrowed avoids heap allocation entirely.

Implementations§

Source§

impl<'a> Url<'a>

Source

pub const NONE: u32 = u32::MAX

Sentinel: component marker absent.

Source

pub const NO_PORT: u32 = u32::MAX

Sentinel: no explicit port.

Source

pub fn blank() -> Url<'static>

Empty placeholder (mostly for tests / incremental builders).

Source

pub fn into_owned(self) -> Url<'static>

Detach from the input lifetime by owning the serialization.

Source

pub fn parse(input: &'a str) -> Result<Self, ParseError>

Parse input according to the WHATWG basic URL parser with no base URL.

§Errors

Returns ParseError::Failure on WHATWG failure, or ParseError::InputTooLong when the input cannot be indexed by u32.

Source

pub fn parse_with_base( input: &'a str, base: Option<&Url<'_>>, ) -> Result<Self, ParseError>

Parse input against an optional absolute base URL.

§Errors

See Url::parse.

Source

pub const fn backing(&self) -> &Backing<'a>

The serialization backing (borrowed or owned).

Source

pub fn as_str(&self) -> &str

The full serialization (WHATWG href).

Source

pub const fn flags(&self) -> UrlFlags

Parser flags for this record.

Source

pub const fn scheme_range(&self) -> Range<usize>

Source

pub fn scheme(&self) -> &str

Scheme without trailing :.

Source

pub fn protocol(&self) -> &str

WHATWG / WPT protocol getter (scheme + ':').

Source

pub fn has_host(&self) -> bool

Source

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

Host serialization without port (None when host is null).

Source

pub fn username(&self) -> &str

Username component (percent-encoded), or "".

Source

pub fn password(&self) -> &str

Password component, or "" when the password slot is absent.

Source

pub const fn port_u16(&self) -> Option<u16>

Source

pub fn port_str(&self) -> String

WHATWG / WPT port getter: decimal string, or "" when null.

Source

pub fn hostname(&self) -> &str

WHATWG / WPT hostname getter (empty string when host is null).

Source

pub fn host_with_port(&self) -> &str

WHATWG / WPT host getter: hostname, plus ":" port when port is non-null.

Source

pub fn path(&self) -> &str

Path / opaque path serialization.

Source

pub fn pathname(&self) -> &str

Alias for Self::path matching the WPT pathname attribute.

Source

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

Query without leading ?, or None when null.

Source

pub fn search(&self) -> &str

WHATWG / WPT search getter ("" or "?" + query).

Source

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

Fragment without leading #, or None when null.

Source

pub fn hash(&self) -> &str

WHATWG / WPT hash getter ("" or "#" + fragment).

Source

pub fn href(&self) -> &str

Serialize this URL record (WHATWG / WPT href).

Source

pub fn percent_decode(raw: &str) -> Cow<'_, str>

Percent-decode raw, allocating only when decoding changes the bytes.

Trait Implementations§

Source§

impl<'a> Clone for Url<'a>

Source§

fn clone(&self) -> Url<'a>

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

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

impl Display for Url<'_>

Source§

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

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

impl Eq for Url<'_>

Source§

impl PartialEq for Url<'_>

Source§

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

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

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

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Url<'a>

§

impl<'a> RefUnwindSafe for Url<'a>

§

impl<'a> Send for Url<'a>

§

impl<'a> Sync for Url<'a>

§

impl<'a> Unpin for Url<'a>

§

impl<'a> UnsafeUnpin for Url<'a>

§

impl<'a> UnwindSafe for Url<'a>

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.