Struct ada_url::Url

source ·
pub struct Url { /* private fields */ }

Implementations§

source§

impl Url

source

pub fn parse(input: &str, base: Option<&str>) -> Result<Url, Error>

Parses the input with an optional base

use ada_url::Url;
let out = Url::parse("https://ada-url.github.io/ada", None)
    .expect("This is a valid URL. Should have parsed it.");
assert_eq!(out.protocol(), "https:");
source

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

Returns whether or not the URL can be parsed or not.

For more information, read WHATWG URL spec

use ada_url::Url;
assert!(Url::can_parse("https://ada-url.github.io/ada", None));
assert!(Url::can_parse("/pathname", Some("https://ada-url.github.io/ada")));
source

pub fn origin(&mut self) -> &str

Return the origin of this URL

For more information, read WHATWG URL spec

use ada_url::Url;

let mut url = Url::parse("blob:https://example.com/foo", None).expect("Invalid URL");
assert_eq!(url.origin(), "https://example.com");
source

pub fn href(&self) -> &str

Return the parsed version of the URL with all components. For more information, read WHATWG URL spec

source

pub fn set_href(&mut self, input: &str) -> bool

source

pub fn username(&self) -> &str

Return the username for this URL as a percent-encoded ASCII string.

For more information, read WHATWG URL spec

use ada_url::Url;

let url = Url::parse("ftp://rms:secret123@example.com", None).expect("Invalid URL");
assert_eq!(url.username(), "rms");
source

pub fn set_username(&mut self, input: &str) -> bool

source

pub fn password(&self) -> &str

Return the password for this URL, if any, as a percent-encoded ASCII string.

For more information, read WHATWG URL spec

use ada_url::Url;

let url = Url::parse("ftp://rms:secret123@example.com", None).expect("Invalid URL");
assert_eq!(url.password(), "secret123");
source

pub fn set_password(&mut self, input: &str) -> bool

source

pub fn port(&self) -> &str

Return the port number for this URL, or an empty string.

For more information, read WHATWG URL spec

use ada_url::Url;

let url = Url::parse("https://example.com", None).expect("Invalid URL");
assert_eq!(url.port(), "");

let url = Url::parse("https://example.com:8080", None).expect("Invalid URL");
assert_eq!(url.port(), "8080");
source

pub fn set_port(&mut self, input: &str) -> bool

source

pub fn hash(&self) -> &str

Return this URL’s fragment identifier, or an empty string. A fragment is the part of the URL with the # symbol. The fragment is optional and, if present, contains a fragment identifier that identifies a secondary resource, such as a section heading of a document. In HTML, the fragment identifier is usually the id attribute of a an element that is scrolled to on load. Browsers typically will not send the fragment portion of a URL to the server.

For more information, read WHATWG URL spec

use ada_url::Url;

let url = Url::parse("https://example.com/data.csv#row=4", None).expect("Invalid URL");
assert_eq!(url.hash(), "#row=4");
assert!(url.has_hash());
source

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

source

pub fn host(&self) -> &str

Return the parsed representation of the host for this URL with an optional port number.

For more information, read WHATWG URL spec

use ada_url::Url;

let url = Url::parse("https://127.0.0.1:8080/index.html", None).expect("Invalid URL");
assert_eq!(url.host(), "127.0.0.1:8080");
source

pub fn set_host(&mut self, input: &str) -> bool

source

pub fn hostname(&self) -> &str

Return the parsed representation of the host for this URL. Non-ASCII domain labels are punycode-encoded per IDNA if this is the host of a special URL, or percent encoded for non-special URLs.

Hostname does not contain port number.

For more information, read WHATWG URL spec

use ada_url::Url;

let url = Url::parse("https://127.0.0.1:8080/index.html", None).expect("Invalid URL");
assert_eq!(url.hostname(), "127.0.0.1");
source

pub fn set_hostname(&mut self, input: &str) -> bool

source

pub fn pathname(&self) -> &str

Return the path for this URL, as a percent-encoded ASCII string.

For more information, read WHATWG URL spec

use ada_url::Url;

let url = Url::parse("https://example.com/api/versions?page=2", None).expect("Invalid URL");
assert_eq!(url.pathname(), "/api/versions");
source

pub fn set_pathname(&mut self, input: &str) -> bool

source

pub fn search(&self) -> &str

Return this URL’s query string, if any, as a percent-encoded ASCII string.

For more information, read WHATWG URL spec

use ada_url::Url;

let url = Url::parse("https://example.com/products?page=2", None).expect("Invalid URL");
assert_eq!(url.search(), "?page=2");

let url = Url::parse("https://example.com/products", None).expect("Invalid URL");
assert_eq!(url.search(), "");
source

pub fn protocol(&self) -> &str

Return the scheme of this URL, lower-cased, as an ASCII string with the ‘:’ delimiter.

For more information, read WHATWG URL spec

use ada_url::Url;

let url = Url::parse("file:///tmp/foo", None).expect("Invalid URL");
assert_eq!(url.protocol(), "file:");
source

pub fn set_protocol(&mut self, input: &str) -> bool

source

pub fn has_credentials(&self) -> bool

source

pub fn has_empty_hostname(&self) -> bool

source

pub fn has_hostname(&self) -> bool

source

pub fn has_non_empty_username(&self) -> bool

source

pub fn has_non_empty_password(&self) -> bool

source

pub fn has_port(&self) -> bool

source

pub fn has_password(&self) -> bool

source

pub fn has_hash(&self) -> bool

Trait Implementations§

source§

impl Drop for Url

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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

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.