pub struct Router { /* private fields */ }Expand description
Path-based request router.
Wraps matchit::Router to map URL path patterns to RouteHandler
implementations. Supports matchit path syntax: /exact,
/prefix/{param}, /{*catch_all}.
Exact paths are matched before parameterized/catch-all patterns, so
registering /.well-known/openid-configuration alongside /{*path}
will always route OIDC discovery before the catch-all.
Implementations§
Source§impl Router
impl Router
pub fn new() -> Self
Sourcepub fn route(self, path: &str, handler: impl RouteHandler + 'static) -> Self
pub fn route(self, path: &str, handler: impl RouteHandler + 'static) -> Self
Register a handler for a path pattern.
Supports matchit syntax: /exact, /prefix/{param}, /{*catch_all}.
Panics if the path conflicts with an already-registered route.
Sourcepub async fn dispatch(&self, req: &RequestInfo<'_>) -> Option<HandlerAction>
pub async fn dispatch(&self, req: &RequestInfo<'_>) -> Option<HandlerAction>
Try to match a path and invoke the matched handler.
On match, the handler receives a RequestInfo with populated
Params extracted from the path pattern.
Returns Some(action) if a route matched and the handler produced an
action. Returns None if no route matched or the handler declined
(returned None).
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Router
impl !RefUnwindSafe for Router
impl !UnwindSafe for Router
impl Send for Router
impl Sync for Router
impl Unpin for Router
impl UnsafeUnpin for Router
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more