[][src]Struct seed::browser::url::Url

pub struct Url { /* fields omitted */ }

URL used for routing.

  • It represents relative URL.
  • Two, almost identical, Urls that differ only with differently advanced internal path or hash path iterators (e.g. next_path_part() was called on one of them) are considered different also during comparison.

(If the features above are problems for you, create an issue)

Implementations

impl Url[src]

pub fn new() -> Self[src]

Creates a new Url with the empty path.

pub fn go_and_push(&self)[src]

Change the browser URL, but do not trigger a page load.

This will add a new entry to the browser history.

References

pub fn go_and_replace(&self)[src]

Change the browser URL, but do not trigger a page load.

This will NOT add a new entry to the browser history.

References

pub fn current() -> Url[src]

Creates a new Url from the one that is currently set in the browser.

pub fn next_path_part(&mut self) -> Option<&str>[src]

Advances the internal path iterator and returns the next path part as Option<&str>.

Example

match url.next_path_part() {
   None => Page::Home,
   Some("report") => Page::Report(page::report::init(url)),
   _ => Page::Unknown(url),
}

pub fn next_hash_path_part(&mut self) -> Option<&str>[src]

Advances the internal hash path iterator and returns the next hash path part as Option<&str>.

Example

match url.next_hash_path_part() {
   None => Page::Home,
   Some("report") => Page::Report(page::report::init(url)),
   _ => Page::Unknown(url),
}

pub fn remaining_path_parts(&mut self) -> Vec<&str>[src]

Collects the internal path iterator and returns it as Vec<&str>.

Example

match url.remaining_path_parts().as_slice() {
   [] => Page::Home,
   ["report", rest @ ..] => {
       match rest {
           ["day"] => Page::ReportDay,
           _ => Page::ReportWeek,
       }
   },
   _ => Page::NotFound,
}

pub fn remaining_hash_path_parts(&mut self) -> Vec<&str>[src]

Collects the internal hash path iterator and returns it as Vec<&str>.

Example

match url.remaining_hash_path_parts().as_slice() {
   [] => Page::Home,
   ["report", rest @ ..] => {
       match rest {
           ["day"] => Page::ReportDay,
           _ => Page::ReportWeek,
       }
   },
   _ => Page::NotFound,
}

pub fn add_path_part(self, path_part: impl Into<String>) -> Self[src]

Adds given path part and returns updated Url.

Example

let link_to_blog = url.add_path_part("blog");

pub fn add_hash_path_part(self, hash_path_part: impl Into<String>) -> Self[src]

Adds given hash path part and returns updated Url. It also changes hash.

Example

let link_to_blog = url.add_hash_path_part("blog");

pub fn to_base_url(&self) -> Self[src]

Clone the Url and strip remaining path parts.

pub fn to_hash_base_url(&self) -> Self[src]

Clone the Url and strip remaining hash path parts.

pub fn set_path<T: ToString>(
    self,
    into_path_iterator: impl IntoIterator<Item = T>
) -> Self
[src]

Sets path and returns updated Url. It also resets internal path iterator.

Example

Url::new().set_path(&["my", "path"])

Refenences

pub fn set_hash_path<T: ToString>(
    self,
    into_hash_path_iterator: impl IntoIterator<Item = T>
) -> Self
[src]

Sets hash path and returns updated Url. It also resets internal hash path iterator and sets hash.

Example

Url::new().set_hash_path(&["my", "path"])

Refenences

pub fn set_hash(self, hash: impl Into<String>) -> Self[src]

Sets hash and returns updated Url. I also sets hash_path.

Example

Url::new().set_hash("my_hash")

References

Sets search and returns updated Url.

Example

Url::new().set_search(UrlSearch::new(vec![
    ("x", vec!["1"]),
    ("sort_by", vec!["date", "name"]),
])

Refenences

pub fn path(&self) -> &[String][src]

Get path.

Refenences

pub fn hash_path(&self) -> &[String][src]

Get hash path.

pub fn hash(&self) -> Option<&String>[src]

Get hash.

References

pub const fn search(&self) -> &UrlSearch[src]

Get search.

Refenences

pub fn search_mut(&mut self) -> &mut UrlSearch[src]

Get mutable search.

Refenences

pub fn go_and_load(&self)[src]

Change the browser URL and trigger a page load.

pub fn go_and_load_with_str(url: impl AsRef<str>)[src]

Change the browser URL and trigger a page load.

Provided url isn't checked and it's passed into location.href.

pub fn reload()[src]

Trigger a page reload.

pub fn reload_and_skip_cache()[src]

Trigger a page reload and force reloading from the server.

pub fn go_back(steps: i32)[src]

Move back in History.

  • steps: 0 only reloads the current page.
  • Negative steps move you forward - use rather Url::go_forward instead.
  • If there is no previous page, this call does nothing.

pub fn go_forward(steps: i32)[src]

Move back in History.

  • steps: 0 only reloads the current page.
  • Negative steps move you back - use rather Url::go_back instead.
  • If there is no next page, this call does nothing.

pub fn skip_base_path(self, path_base: &[String]) -> Self[src]

If the current Url's path prefix is equal to path_base, then reset the internal path iterator and advance it to skip the prefix (aka path_base).

It's used mostly by Seed internals, but it can be useful in combination with orders.clone_base_path().

pub fn decode_uri_component(
    component: impl AsRef<str>
) -> Result<String, JsValue>
[src]

Decodes a Uniform Resource Identifier (URI) component. Aka percent-decoding.

Note: All components are automatically decoded when it's possible. You can find undecodable components in the vector returned from methods invalid_components or invalid_components_mut.

Example

Url::decode_uri_component("Hello%20G%C3%BCnter"); // => "Hello Günter"

Errors

Returns error when decoding fails - e.g. "Error: malformed URI sequence".

pub fn invalid_components(&self) -> &[String][src]

Get invalid components.

Undecodable / unparsable components are invalid.

pub fn invalid_components_mut(&mut self) -> &mut Vec<String>[src]

Get mutable invalid components.

Undecodable / unparsable components are invalid.

Trait Implementations

impl Clone for Url[src]

impl Debug for Url[src]

impl Default for Url[src]

impl<'de> Deserialize<'de> for Url[src]

impl Display for Url[src]

Url components are automatically encoded.

impl<'_> From<&'_ Url> for Url[src]

fn from(url: &Url) -> Self[src]

Creates a new Url from the browser native url. Url's components are decoded if possible. When decoding fails, the component is cloned into invalid_components and the original value is used.

impl<'a> From<&'a Url> for Cow<'a, Url>[src]

impl<'a> From<Url> for Request<'a>[src]

impl<'a> From<Url> for Cow<'a, Url>[src]

impl FromStr for Url[src]

type Err = String

The associated error which can be returned from parsing.

fn from_str(str_url: &str) -> Result<Self, Self::Err>[src]

Creates a new Url from &str.

Errors

Returns error when url cannot be parsed.

Note: When only some components are undecodable, no error is returned - that components are saved into the Urls invalid_components - see methods Url::invalid_components and Url::invalid_components_mut.

impl PartialEq<Url> for Url[src]

impl Serialize for Url[src]

impl StructuralPartialEq for Url[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Sealed<T> for T where
    T: ?Sized

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,