pub struct RouteEntry {
pub method: Method,
pub path: String,
/* private fields */
}Expand description
A registered route with its handler.
Fields§
§method: MethodThe HTTP method for this route.
path: StringThe path pattern for this route.
Implementations§
Source§impl RouteEntry
impl RouteEntry
Sourcepub fn new<H, Fut>(method: Method, path: impl Into<String>, handler: H) -> Self
pub fn new<H, Fut>(method: Method, path: impl Into<String>, handler: H) -> Self
Creates a new route entry from a handler whose future is 'static
(it does not borrow the context or request beyond the call).
Plain fn(&RequestContext, &mut Request) -> Ready<Response> handlers and
async fn handlers that clone what they need fit here. Handlers that must
borrow ctx/req across an .await use RouteEntry::new_boxed.
Sourcepub fn new_boxed<H>(method: Method, path: impl Into<String>, handler: H) -> Self
pub fn new_boxed<H>(method: Method, path: impl Into<String>, handler: H) -> Self
Creates a new route entry from a handler that returns a BoxFuture
borrowing the context and request for the call’s duration.
This is the general form: extractor-based handlers await FromRequest
on req and pass ctx.cx() through, so their futures are tied to the
call. #[get]-style proc-macro routes are built this way via
RouteEntry::from_route.
Sourcepub fn from_route<H>(route: Route, handler: H) -> Self
pub fn from_route<H>(route: Route, handler: H) -> Self
Creates a new route entry from a fastapi_router::Route metadata object.
This is the constructor proc-macro generated routes use, since it preserves
OpenAPI metadata (operation_id, tags, request body, etc). The handler has
the borrowing form of RouteEntry::new_boxed.
Sourcepub fn route_meta(&self) -> Option<&Route>
pub fn route_meta(&self) -> Option<&Route>
Returns the preserved route metadata, if any.
Sourcepub async fn call(&self, ctx: &RequestContext, req: &mut Request) -> Response
pub async fn call(&self, ctx: &RequestContext, req: &mut Request) -> Response
Calls the handler with the given context and request.
Trait Implementations§
Source§impl Clone for RouteEntry
impl Clone for RouteEntry
Source§fn clone(&self) -> RouteEntry
fn clone(&self) -> RouteEntry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more