-
SummaryI want to use trait to enforce all the routes to be implemented and to use a proc_macro to generate the make_router function but axum show that the trait function dont implement the // #[routes(prefix = "/api")
trait Routes {
async fn handle() -> &'static str {
"hello world"
}
// generated by the #[routes(prefix = "/api")] macro
fn make_router() -> (&'static str, axum::Router) {
let router = axum::Router::new().route("/handle", axum::routing::get(Self::handle));
("/api", router)
}
} axum version0.8.1 |
Beta Was this translation helpful? Give feedback.
Answered by
DxUr
Apr 25, 2025
Replies: 1 comment 1 reply
-
Sorry, but I don't understand what you're trying to achieve, what you did and what error you observed. Can you create a fuller example? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have fixed the problem by now, the idea is to declare the routes on a common crate between the front end and backend then using a macro the traint which contains the routes get compiled to fetch requests on frontend and a trait that you should implement on the backend i want to automatically generate a function on the trait
make_router
so i dont need to bind the routes by hand i fix it passing the struct that will implement the trait to the macro so the macro can generate an impl block for it, basically trait items do not implement theHandler
trait so i cant use them directly.After a week of developing I found it useless since i need to set some middelwares.
this is an example on how …