Struct Location

Source
pub struct Location(/* private fields */);
Expand description

The Location interface represents the location (URL) of the object it is linked to. Changes done on it are reflected on the object it relates to. Both the Document and Window interface have such a linked Location, accessible via Document::location and Window::location respectively.

Note that all Location methods can return a SecurityError if the Location object’s relevant Document’s origin is not same origin-domain with the entry settings object’s origin. See: https://html.spec.whatwg.org/#dom-location-href

(JavaScript docs)

Implementations§

Source§

impl Location

Source

pub fn href(&self) -> Result<String, SecurityError>

The entire URL.

(JavaScript docs)

Source

pub fn origin(&self) -> Result<String, SecurityError>

Returns a String containing the Unicode serialization of the origin of the represented URL, that is:

  • For URL using the http or https, the scheme followed by '://', followed by the domain, followed by ':', followed by the port (the default port, 80 and 443 respectively, if explicitely specified);
  • For URL using file: scheme, the value is browser dependant.
  • For URL using the blob: scheme, the origin of the URL following blob:. E.g “blob:https://mozilla.org” will have “https://mozilla.org”.

(JavaScript docs)

Source

pub fn protocol(&self) -> Result<String, SecurityError>

Returns a String representing the protocol scheme of the URL, including the final ‘:’.

Example: http:

(JavaScript docs)

Source

pub fn host(&self) -> Result<String, SecurityError>

Returns a String containing the host (i.e. hostname) and then, if the port of the URL is nonempty, a ‘:’, and the port of the URL.

Example: hitchhikers.com:4242

(JavaScript docs)

Source

pub fn hostname(&self) -> Result<String, SecurityError>

Returns a String which is the domain of the URL

Example: mozilla.com

(JavaScript docs)

Source

pub fn port(&self) -> Result<String, SecurityError>

Returns a String containing the port number or "" if there is no port.

(JavaScript docs)

Source

pub fn pathname(&self) -> Result<String, SecurityError>

Returns a String containing an initial ‘/’ followed by the path of the URL.

(JavaScript docs)

Source

pub fn search(&self) -> Result<String, SecurityError>

Returns a String which is a search string, also called a query string, that is a String containing a ‘?’ followed by the parameters of the URL.

These can then be further parsed via another library.

(JavaScript docs)

Source

pub fn hash(&self) -> Result<String, SecurityError>

Returns a String containing a ‘#’ followed by the fragment identifier of the URL. The fragment is not percent-decoded.

(JavaScript docs)

Trait Implementations§

Source§

impl AsRef<Reference> for Location

Source§

fn as_ref(&self) -> &Reference

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

impl Clone for Location

Source§

fn clone(&self) -> Location

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 Debug for Location

Source§

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

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

impl From<Location> for Reference

Source§

fn from(value: Location) -> Self

Converts to this type from the input type.
Source§

impl InstanceOf for Location

Source§

fn instance_of(reference: &Reference) -> bool

Checks whenever a given Reference if of type Self.
Source§

impl PartialEq for Location

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl ReferenceType for Location

Source§

unsafe fn from_reference_unchecked(reference: Reference) -> Self

Converts a given reference into a concrete reference-like wrapper. Doesn’t do any type checking; highly unsafe to use!
Source§

impl<'_r> TryFrom<&'_r Reference> for Location

Source§

type Error = ConversionError

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

fn try_from(reference: &Reference) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'_r> TryFrom<&'_r Value> for Location

Source§

type Error = ConversionError

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

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Location> for Reference

Source§

type Error = Void

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

fn try_from(value: Location) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Reference> for Location

Source§

type Error = ConversionError

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

fn try_from(reference: Reference) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for Location

Source§

type Error = ConversionError

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for Location

Source§

impl JsSerialize for Location

Source§

impl StructuralPartialEq for Location

Auto Trait Implementations§

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