Struct urlpattern::UrlPattern
source · [−]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
sourceimpl<R: RegExp> UrlPattern<R>
impl<R: RegExp> UrlPattern<R>
sourcepub fn parse(init: UrlPatternInit) -> Result<Self, Error>
pub fn parse(init: UrlPatternInit) -> Result<Self, Error>
Parse a UrlPatternInit into a UrlPattern.
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
.
Trait Implementations
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more