pub struct Router { /* private fields */ }Implementations§
Source§impl Router
impl Router
pub fn new() -> Self
Sourcepub fn with_host(self, host: &str) -> Self
pub fn with_host(self, host: &str) -> Self
Restrict this router to requests whose SNI hostname (TLS) or Host
header (plain HTTP) matches host. Call before registering routes.
Sourcepub fn delete<F>(self, pattern: &str, handler: F) -> Self
pub fn delete<F>(self, pattern: &str, handler: F) -> Self
Register a DELETE handler for pattern.
Sourcepub fn route_entries(&self) -> Vec<RouteInfo>
pub fn route_entries(&self) -> Vec<RouteInfo>
Return a snapshot of all registered routes as (method, pattern) pairs.
Patterns are reconstructed from parsed segments, so the output exactly
matches what was passed to .get(), .post(), etc. at registration time.
Sourcepub fn handle(
&self,
request: &Request,
connection: &ConnectionInfo,
) -> Option<Response>
pub fn handle( &self, request: &Request, connection: &ConnectionInfo, ) -> Option<Response>
Try to match request against registered routes in registration order.
Returns Some(response) on the first match, None if no route matches.
The query string is stripped before matching; only the path is used.
When .with_host() is set, this returns None immediately unless the
request’s SNI hostname (TLS) or Host header (plain HTTP) matches.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Router
impl !UnwindSafe for Router
impl Freeze 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
Mutably borrows from an owned value. Read more