Skip to main content

serverust_core/
route.rs

1use axum::routing::MethodRouter;
2use utoipa::openapi::{HttpMethod, path::Operation};
3
4use crate::container::Container;
5
6/// Metadata de uma rota registrável no [`crate::App`].
7///
8/// O `MethodRouter` é parametrizado pelo [`Container`] (state do App) para
9/// que handlers possam extrair serviços via `State<Arc<dyn Trait>>`.
10pub struct Route {
11    pub path: &'static str,
12    pub method: HttpMethod,
13    pub method_router: MethodRouter<Container>,
14    pub operation: Operation,
15}
16
17impl Route {
18    pub fn new(
19        path: &'static str,
20        method: HttpMethod,
21        method_router: MethodRouter<Container>,
22        operation: Operation,
23    ) -> Self {
24        Self {
25            path,
26            method,
27            method_router,
28            operation,
29        }
30    }
31}
32
33/// Implementado pelas structs geradas pelas macros `#[get]`, `#[post]`, etc.
34///
35/// Permite passar o nome do handler diretamente para `App::route(handler)`.
36pub trait IntoRoute {
37    fn into_route(self) -> Route;
38}