pub struct UrlPattern<R: RegExp = Regex> { /* private fields */ }
Expand description

A UrlPattern that can be matched against.

Examples

use urlpattern::UrlPattern;
use urlpattern::UrlPatternInit;
use urlpattern::UrlPatternMatchInput;

// Create the UrlPattern to match against.
let init = UrlPatternInit {
  pathname: Some("/users/:id".to_owned()),
  ..Default::default()
};
let pattern = <UrlPattern>::parse(init).unwrap();

// Match the pattern against a URL.
let url = "https://example.com/users/123".parse().unwrap();
let result = pattern.exec(UrlPatternMatchInput::Url(url)).unwrap().unwrap();
assert_eq!(result.pathname.groups.get("id").unwrap(), "123");

Implementations

Parse a UrlPatternInit into a UrlPattern.

The pattern used to match against the protocol of the URL.

The pattern used to match against the username of the URL.

The pattern used to match against the password of the URL.

The pattern used to match against the hostname of the URL.

The pattern used to match against the port of the URL.

The pattern used to match against the pathname of the URL.

The pattern used to match against the search string of the URL.

The pattern used to match against the hash fragment of the URL.

Test if a given [UrlPatternInput] (with optional base url), matches the pattern.

Execute the pattern against a [UrlPatternInput] (with optional base url), returning a UrlPatternResult if the pattern matches. If the pattern doesn’t match, returns None.

Trait Implementations

Formats the value using the given formatter. 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 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.