pub struct HostRouter { /* private fields */ }Expand description
Routes requests to different axum Routers based on the Host header.
Supports exact host matches (acme.com, app.acme.com) and single-level
wildcard subdomains (*.acme.com). Both use HashMap lookups for O(1)
matching.
§Panics
The host and fallback methods panic if
called after the HostRouter has been cloned or converted. Complete all
route registration before passing the router to server::http()
or cloning it.
The host method also panics on:
- Duplicate exact host patterns
- Duplicate wildcard suffixes
- Invalid wildcard patterns (suffix must contain at least one dot)
§Example
use modo::server::HostRouter;
use axum::Router;
let app = HostRouter::new()
.host("acme.com", Router::new())
.host("app.acme.com", Router::new())
.host("*.acme.com", Router::new())
.fallback(Router::new());Implementations§
Source§impl HostRouter
impl HostRouter
Sourcepub fn host(self, pattern: &str, router: Router) -> Self
pub fn host(self, pattern: &str, router: Router) -> Self
Register a host pattern with a router.
Exact patterns (e.g. "acme.com", "app.acme.com") match the host
literally. Wildcard patterns (e.g. "*.acme.com") match any single
subdomain level.
§Panics
- If an exact host is registered twice.
- If a wildcard suffix is registered twice.
- If a wildcard suffix contains no dot (e.g.
"*.com").
Trait Implementations§
Source§impl Clone for HostRouter
impl Clone for HostRouter
Source§fn clone(&self) -> HostRouter
fn clone(&self) -> HostRouter
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for HostRouter
impl Debug for HostRouter
Source§impl Default for HostRouter
impl Default for HostRouter
Source§impl From<HostRouter> for Router
impl From<HostRouter> for Router
Source§fn from(host_router: HostRouter) -> Router
fn from(host_router: HostRouter) -> Router
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for HostRouter
impl !RefUnwindSafe for HostRouter
impl Send for HostRouter
impl Sync for HostRouter
impl Unpin for HostRouter
impl UnsafeUnpin for HostRouter
impl !UnwindSafe for HostRouter
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