urlpattern

Struct UrlPattern

Source
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>

Source

pub fn parse( init: UrlPatternInit, options: UrlPatternOptions, ) -> Result<Self, Error>

Parse a UrlPatternInit into a UrlPattern.

Source

pub(crate) fn parse_internal( init: UrlPatternInit, report_regex_errors: bool, options: UrlPatternOptions, ) -> Result<Self, Error>

Source

pub fn protocol(&self) -> &str

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

Source

pub fn username(&self) -> &str

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

Source

pub fn password(&self) -> &str

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

Source

pub fn hostname(&self) -> &str

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

Source

pub fn port(&self) -> &str

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

Source

pub fn pathname(&self) -> &str

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

Source

pub fn search(&self) -> &str

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

Source

pub fn hash(&self) -> &str

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

Source

pub fn has_regexp_groups(&self) -> bool

Returns whether the URLPattern contains one or more groups which uses regular expression matching.

Source

pub fn test(&self, input: UrlPatternMatchInput) -> Result<bool, Error>

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

Source

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.

Source

pub(crate) fn matches( &self, input: UrlPatternMatchInput, ) -> Result<Option<UrlPatternResult>, Error>

Trait Implementations§

Source§

impl<R: Debug + RegExp> Debug for UrlPattern<R>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T