pub struct PathRouter { /* private fields */ }Expand description
A path-based http request router
A Handler that matches the URL of each incoming request against a list of registered patterns and calls the matching handler, if one exists.
If no matching path is found, the handler returns a 404 Not Found.
Implementations§
Source§impl PathRouter
impl PathRouter
Sourcepub fn register<H>(&mut self, path: &str, handler: H)where
H: Handler + 'static,
pub fn register<H>(&mut self, path: &str, handler: H)where
H: Handler + 'static,
Registers a handler that is invoked on incoming requests path.
Paths support basic segment matching. Matched path values are included in the request object
§Path Matching Syntax
Matching an exact path
This will only match requests where the path is “/a/b”. This is not a prefix match.
use claro::{handler::PathRouter, Request, Response};
PathRouter::new().register("/a/b", |_: &mut Request, _: &mut Response| {});Matching a segment within a path
This will match requests like /a/b/c and /a/blahwhatever/c.
use claro::{handler::PathRouter, Request, Response};
PathRouter::new().register("/a/{next}/c", |_: &mut Request, _: &mut Response| {});Prefix matching
This will match requests like /a/whatever and /a/blah/blah/blah
use claro::{handler::PathRouter, Request, Response};
PathRouter::new().register("/a/{*rest}", |_: &mut Request, _: &mut Response| {});Trait Implementations§
Source§impl Default for PathRouter
impl Default for PathRouter
Source§fn default() -> PathRouter
fn default() -> PathRouter
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !Freeze for PathRouter
impl !RefUnwindSafe for PathRouter
impl Send for PathRouter
impl Sync for PathRouter
impl Unpin for PathRouter
impl !UnwindSafe for PathRouter
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