pub struct Router { /* private fields */ }Expand description
Hyper-backed route registry: stores routes with per-route middlewares,
runs global middlewares for every request, and dispatches by method and path.
A trailing /* on a route path acts as a prefix wildcard when matching.
Implementations§
Source§impl Router
impl Router
Sourcepub fn set_test_client_handler(&mut self, handler: BoxHandler)
pub fn set_test_client_handler(&mut self, handler: BoxHandler)
Installs the reserved test-client interceptor used for documentation-driven test runs.
Sourcepub fn mount<T, F, Fut>(
&mut self,
base_path: &str,
version: u32,
path: &str,
has_body: bool,
method: Method,
description: RouteDescription,
handler: F,
middlewares: Vec<Middleware>,
)where
T: Serialize + Send + Sync + 'static,
F: Fn(CorrelationContext) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<ServiceResult<T>, ErrorResult>> + Send + 'static,
pub fn mount<T, F, Fut>(
&mut self,
base_path: &str,
version: u32,
path: &str,
has_body: bool,
method: Method,
description: RouteDescription,
handler: F,
middlewares: Vec<Middleware>,
)where
T: Serialize + Send + Sync + 'static,
F: Fn(CorrelationContext) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<ServiceResult<T>, ErrorResult>> + Send + 'static,
Registers a typed handler at base_path + version + path for method.
Type parameter T is the ServiceResult payload; F/Fut describes the
Fn(CorrelationContext) async handler returning Result<ServiceResult<T>, ErrorResult>.
The handler receives only the context: body, headers, and query parameters are
attached at dispatch, so use ctx.body::<T>(), ctx.header(), or ctx.query_param().
Registers the description for documentation, installs per-route rate-limit
middleware when description.rate_limit is set, and enforces declared file-part
count caps before the handler runs.
Panics if has_body is set without a declared request body or file parameter.
router.mount("/users", 1, "/:id", false, Method::GET, desc, handler, vec![]);Sourcepub fn mount_typed<F, Fut>(
&mut self,
base_path: &str,
version: u32,
path: &str,
method: Method,
description: RouteDescription,
handler: F,
middlewares: Vec<Middleware>,
)where
F: Fn(CorrelationContext) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<Box<dyn TypedServiceResult>, ErrorResult>> + Send + 'static,
pub fn mount_typed<F, Fut>(
&mut self,
base_path: &str,
version: u32,
path: &str,
method: Method,
description: RouteDescription,
handler: F,
middlewares: Vec<Middleware>,
)where
F: Fn(CorrelationContext) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<Box<dyn TypedServiceResult>, ErrorResult>> + Send + 'static,
Registers a handler returning heterogeneous payloads as Box<dyn TypedServiceResult>.
Use this when one handler returns different ServiceResult<T> shapes; prefer
Router::mount when the result type is statically known.
Like Router::mount, the handler takes only the CorrelationContext.
Sourcepub fn mount_raw(
&mut self,
base_path: &str,
version: u32,
path: &str,
method: Method,
handler: BoxHandler,
middlewares: Vec<Middleware>,
)
pub fn mount_raw( &mut self, base_path: &str, version: u32, path: &str, method: Method, handler: BoxHandler, middlewares: Vec<Middleware>, )
Registers a pre-built BoxHandler at the resolved path with the given middlewares.
A trailing /* on the resolved path acts as a prefix wildcard when matching.
Unlike Router::mount, this performs no docs registration and imposes no
body contract, making it suitable for static-asset serving and custom handlers.
Sourcepub fn mount_static(
&mut self,
base_path: &str,
version: u32,
path: &str,
fs_path: String,
middlewares: Vec<Middleware>,
)
pub fn mount_static( &mut self, base_path: &str, version: u32, path: &str, fs_path: String, middlewares: Vec<Middleware>, )
Serves files under fs_path at base_path + version + path with a /* wildcard.
Requests for / resolve to index.html when present; missing files fall back
to a plain-text placeholder response instead of a 404.
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<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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