pub trait RouterFns {
// Required method
fn routes(
&mut self,
) -> &mut HashMap<String, HashMap<HttpMethods, Arc<dyn Fn(HttpRequest, HttpResponse) -> Pin<Box<dyn Future<Output = HttpResponse> + Send + 'static>> + Send + Sync + 'static>>>;
// Provided methods
fn add_route<F, HFut>(
&mut self,
method: HttpMethods,
path: &str,
handler: F,
)
where F: Fn(HttpRequest, HttpResponse) -> HFut + Send + Sync + 'static,
HFut: Future<Output = HttpResponse> + Send + 'static { ... }
fn get<F, HFut, P>(&mut self, path: &str, handler: F) -> &mut Self
where F: Fn(P, HttpResponse) -> HFut + Send + Sync + 'static,
HFut: Future<Output = HttpResponse> + Send + 'static,
P: ExtractFromOwned + Send + 'static { ... }
fn options<F, HFut, P>(&mut self, path: &str, handler: F) -> &mut Self
where F: Fn(P, HttpResponse) -> HFut + Send + Sync + 'static,
HFut: Future<Output = HttpResponse> + Send + 'static,
P: ExtractFromOwned + Send + 'static { ... }
fn post<F, HFut, P>(&mut self, path: &str, handler: F) -> &mut Self
where F: Fn(P, HttpResponse) -> HFut + Send + Sync + 'static,
HFut: Future<Output = HttpResponse> + Send + 'static,
P: ExtractFromOwned + Send + 'static { ... }
fn put<F, HFut, P>(&mut self, path: &str, handler: F) -> &mut Self
where F: Fn(P, HttpResponse) -> HFut + Send + Sync + 'static,
HFut: Future<Output = HttpResponse> + Send + 'static,
P: ExtractFromOwned + Send + 'static { ... }
fn delete<F, HFut, P>(&mut self, path: &str, handler: F) -> &mut Self
where F: Fn(P, HttpResponse) -> HFut + Send + Sync + 'static,
HFut: Future<Output = HttpResponse> + Send + 'static,
P: ExtractFromOwned + Send + 'static { ... }
fn head<F, HFut, P>(&mut self, path: &str, handler: F) -> &mut Self
where F: Fn(P, HttpResponse) -> HFut + Send + Sync + 'static,
HFut: Future<Output = HttpResponse> + Send + 'static,
P: ExtractFromOwned + Send + 'static { ... }
fn patch<F, HFut, P>(&mut self, path: &str, handler: F) -> &mut Self
where F: Fn(P, HttpResponse) -> HFut + Send + Sync + 'static,
HFut: Future<Output = HttpResponse> + Send + 'static,
P: ExtractFromOwned + Send + 'static { ... }
fn get_routes(
&mut self,
path: &str,
method: HttpMethods,
) -> Option<&Arc<dyn Fn(HttpRequest, HttpResponse) -> Pin<Box<dyn Future<Output = HttpResponse> + Send + 'static>> + Send + Sync + 'static>> { ... }
fn add_route_with_extraction<F, HFut, P>(
&mut self,
method: HttpMethods,
path: &str,
handler: F,
)
where F: Fn(P, HttpResponse) -> HFut + Send + Sync + 'static,
HFut: Future<Output = HttpResponse> + Send + 'static,
P: ExtractFromOwned + Send + 'static { ... }
}Expand description
Trait providing routing functionality for applications and routers.
This trait defines methods for managing and registering HTTP routes, including adding handlers for specific HTTP methods and retrieving registered route handlers. Types that implement this trait must provide access to their internal route storage.
Required Methods§
Sourcefn routes(
&mut self,
) -> &mut HashMap<String, HashMap<HttpMethods, Arc<dyn Fn(HttpRequest, HttpResponse) -> Pin<Box<dyn Future<Output = HttpResponse> + Send + 'static>> + Send + Sync + 'static>>>
fn routes( &mut self, ) -> &mut HashMap<String, HashMap<HttpMethods, Arc<dyn Fn(HttpRequest, HttpResponse) -> Pin<Box<dyn Future<Output = HttpResponse> + Send + 'static>> + Send + Sync + 'static>>>
Get a mutable reference to the internal routes map.
This is used by trait default implementations to access or modify the underlying route storage for this type.
Provided Methods§
Sourcefn add_route<F, HFut>(&mut self, method: HttpMethods, path: &str, handler: F)where
F: Fn(HttpRequest, HttpResponse) -> HFut + Send + Sync + 'static,
HFut: Future<Output = HttpResponse> + Send + 'static,
fn add_route<F, HFut>(&mut self, method: HttpMethods, path: &str, handler: F)where
F: Fn(HttpRequest, HttpResponse) -> HFut + Send + Sync + 'static,
HFut: Future<Output = HttpResponse> + Send + 'static,
Register a handler for a specific HTTP method/path.
§Type Parameters
F- Function that handles the request, with the signature(HttpRequest, HttpResponse) -> HFutHFut- Future outputting the finalHttpResponse
§Arguments
method- HTTP method (GET, POST, etc.)path- Route pattern (e.g., “/users”)handler- Handler function
If a handler for a given method/path already exists, it is replaced.
Sourcefn get<F, HFut, P>(&mut self, path: &str, handler: F) -> &mut Selfwhere
F: Fn(P, HttpResponse) -> HFut + Send + Sync + 'static,
HFut: Future<Output = HttpResponse> + Send + 'static,
P: ExtractFromOwned + Send + 'static,
fn get<F, HFut, P>(&mut self, path: &str, handler: F) -> &mut Selfwhere
F: Fn(P, HttpResponse) -> HFut + Send + Sync + 'static,
HFut: Future<Output = HttpResponse> + Send + 'static,
P: ExtractFromOwned + Send + 'static,
Register a GET handler for a path, with extractor integration.
§Example
use ripress::{app::App, context::{HttpRequest, HttpResponse}, types::RouterFns};
async fn handler(req: HttpRequest, res: HttpResponse) -> HttpResponse {
res.ok().text("Hello, World!")
}
let mut app = App::new();
app.get("/hello", handler);Sourcefn options<F, HFut, P>(&mut self, path: &str, handler: F) -> &mut Selfwhere
F: Fn(P, HttpResponse) -> HFut + Send + Sync + 'static,
HFut: Future<Output = HttpResponse> + Send + 'static,
P: ExtractFromOwned + Send + 'static,
fn options<F, HFut, P>(&mut self, path: &str, handler: F) -> &mut Selfwhere
F: Fn(P, HttpResponse) -> HFut + Send + Sync + 'static,
HFut: Future<Output = HttpResponse> + Send + 'static,
P: ExtractFromOwned + Send + 'static,
Register an OPTIONS handler for a path, with extractor integration.
Sourcefn post<F, HFut, P>(&mut self, path: &str, handler: F) -> &mut Selfwhere
F: Fn(P, HttpResponse) -> HFut + Send + Sync + 'static,
HFut: Future<Output = HttpResponse> + Send + 'static,
P: ExtractFromOwned + Send + 'static,
fn post<F, HFut, P>(&mut self, path: &str, handler: F) -> &mut Selfwhere
F: Fn(P, HttpResponse) -> HFut + Send + Sync + 'static,
HFut: Future<Output = HttpResponse> + Send + 'static,
P: ExtractFromOwned + Send + 'static,
Register a POST handler for a path, with extractor integration.
Sourcefn put<F, HFut, P>(&mut self, path: &str, handler: F) -> &mut Selfwhere
F: Fn(P, HttpResponse) -> HFut + Send + Sync + 'static,
HFut: Future<Output = HttpResponse> + Send + 'static,
P: ExtractFromOwned + Send + 'static,
fn put<F, HFut, P>(&mut self, path: &str, handler: F) -> &mut Selfwhere
F: Fn(P, HttpResponse) -> HFut + Send + Sync + 'static,
HFut: Future<Output = HttpResponse> + Send + 'static,
P: ExtractFromOwned + Send + 'static,
Register a PUT handler for a path, with extractor integration.
Sourcefn delete<F, HFut, P>(&mut self, path: &str, handler: F) -> &mut Selfwhere
F: Fn(P, HttpResponse) -> HFut + Send + Sync + 'static,
HFut: Future<Output = HttpResponse> + Send + 'static,
P: ExtractFromOwned + Send + 'static,
fn delete<F, HFut, P>(&mut self, path: &str, handler: F) -> &mut Selfwhere
F: Fn(P, HttpResponse) -> HFut + Send + Sync + 'static,
HFut: Future<Output = HttpResponse> + Send + 'static,
P: ExtractFromOwned + Send + 'static,
Register a DELETE handler for a path, with extractor integration.
Sourcefn head<F, HFut, P>(&mut self, path: &str, handler: F) -> &mut Selfwhere
F: Fn(P, HttpResponse) -> HFut + Send + Sync + 'static,
HFut: Future<Output = HttpResponse> + Send + 'static,
P: ExtractFromOwned + Send + 'static,
fn head<F, HFut, P>(&mut self, path: &str, handler: F) -> &mut Selfwhere
F: Fn(P, HttpResponse) -> HFut + Send + Sync + 'static,
HFut: Future<Output = HttpResponse> + Send + 'static,
P: ExtractFromOwned + Send + 'static,
Register a HEAD handler for a path, with extractor integration.
Sourcefn patch<F, HFut, P>(&mut self, path: &str, handler: F) -> &mut Selfwhere
F: Fn(P, HttpResponse) -> HFut + Send + Sync + 'static,
HFut: Future<Output = HttpResponse> + Send + 'static,
P: ExtractFromOwned + Send + 'static,
fn patch<F, HFut, P>(&mut self, path: &str, handler: F) -> &mut Selfwhere
F: Fn(P, HttpResponse) -> HFut + Send + Sync + 'static,
HFut: Future<Output = HttpResponse> + Send + 'static,
P: ExtractFromOwned + Send + 'static,
Register a PATCH handler for a path, with extractor integration.
Sourcefn get_routes(
&mut self,
path: &str,
method: HttpMethods,
) -> Option<&Arc<dyn Fn(HttpRequest, HttpResponse) -> Pin<Box<dyn Future<Output = HttpResponse> + Send + 'static>> + Send + Sync + 'static>>
fn get_routes( &mut self, path: &str, method: HttpMethods, ) -> Option<&Arc<dyn Fn(HttpRequest, HttpResponse) -> Pin<Box<dyn Future<Output = HttpResponse> + Send + 'static>> + Send + Sync + 'static>>
Retrieve the route handler for a given path/method, if one is registered.
Returns Some(&Handler) if a matching handler exists, else None.
Sourcefn add_route_with_extraction<F, HFut, P>(
&mut self,
method: HttpMethods,
path: &str,
handler: F,
)where
F: Fn(P, HttpResponse) -> HFut + Send + Sync + 'static,
HFut: Future<Output = HttpResponse> + Send + 'static,
P: ExtractFromOwned + Send + 'static,
fn add_route_with_extraction<F, HFut, P>(
&mut self,
method: HttpMethods,
path: &str,
handler: F,
)where
F: Fn(P, HttpResponse) -> HFut + Send + Sync + 'static,
HFut: Future<Output = HttpResponse> + Send + 'static,
P: ExtractFromOwned + Send + 'static,
Internal helper: Register a handler using extractor integration.
This wraps the user’s handler so the extractor type P is populated from the HttpRequest.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.