pub struct UrlPattern<R: RegExp = Regex> {
pub(crate) protocol: Component<R>,
pub(crate) username: Component<R>,
pub(crate) password: Component<R>,
pub(crate) hostname: Component<R>,
pub(crate) port: Component<R>,
pub(crate) pathname: Component<R>,
pub(crate) search: Component<R>,
pub(crate) hash: Component<R>,
}
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, Default::default()).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().as_ref().unwrap(), "123");
Fields§
§protocol: Component<R>
§username: Component<R>
§password: Component<R>
§hostname: Component<R>
§port: Component<R>
§pathname: Component<R>
§search: Component<R>
§hash: Component<R>
Implementations§
Source§impl<R: RegExp> UrlPattern<R>
impl<R: RegExp> UrlPattern<R>
Sourcepub fn parse(
init: UrlPatternInit,
options: UrlPatternOptions,
) -> Result<Self, Error>
pub fn parse( init: UrlPatternInit, options: UrlPatternOptions, ) -> Result<Self, Error>
Parse a UrlPatternInit into a UrlPattern.
pub(crate) fn parse_internal( init: UrlPatternInit, report_regex_errors: bool, options: UrlPatternOptions, ) -> Result<Self, Error>
Sourcepub fn has_regexp_groups(&self) -> bool
pub fn has_regexp_groups(&self) -> bool
Returns whether the URLPattern contains one or more groups which uses regular expression matching.
Sourcepub fn test(&self, input: UrlPatternMatchInput) -> Result<bool, Error>
pub fn test(&self, input: UrlPatternMatchInput) -> Result<bool, Error>
Test if a given [UrlPatternInput] (with optional base url), matches the pattern.
Sourcepub fn exec(
&self,
input: UrlPatternMatchInput,
) -> Result<Option<UrlPatternResult>, Error>
pub fn exec( &self, input: UrlPatternMatchInput, ) -> Result<Option<UrlPatternResult>, Error>
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
.
pub(crate) fn matches( &self, input: UrlPatternMatchInput, ) -> Result<Option<UrlPatternResult>, Error>
Trait Implementations§
Auto Trait Implementations§
impl<R> Freeze for UrlPattern<R>where
R: Freeze,
impl<R> RefUnwindSafe for UrlPattern<R>where
R: RefUnwindSafe,
impl<R> Send for UrlPattern<R>where
R: Send,
impl<R> Sync for UrlPattern<R>where
R: Sync,
impl<R> Unpin for UrlPattern<R>where
R: Unpin,
impl<R> UnwindSafe for UrlPattern<R>where
R: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more