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

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

Creates a new Url with the empty path.

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

This will add a new entry to the browser history.

References

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

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

References

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

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),
}

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),
}

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

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

Adds given path part and returns updated Url.

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

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

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

Clone the Url and strip remaining path parts.

Clone the Url and strip remaining hash path parts.

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

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

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"])
References

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"]),
])
References

Get path.

References

Get hash path.

Get hash.

References

Get search.

References

Get mutable search.

References

Change the browser URL and trigger a page load.

Change the browser URL and trigger a page load.

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

Trigger a page reload.

Trigger a page reload and force reloading from the server.

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.

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.

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

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

It’s used mostly by Seed internals.

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

Encode to a Uniform Resource Identifier (URI) component. Aka percent-encoding.

Note: All components are automatically encoded in Display implementation for Url - i.e. url.to_string() returns encoded url.

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

Get invalid components.

Undecodable / unparsable components are invalid.

Get mutable invalid components.

Undecodable / unparsable components are invalid.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Deserialize this value from the given Serde deserializer. Read more

All components are automatically encoded.

Formats the value using the given formatter. Read more

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.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

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.

The associated error which can be returned from parsing.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.