0

I'm trying to make a server with Rust for learning purposes and one of the things I'd like to do is build a router so in main I don't have 50 .service(route) calls. That way each module can pass up a method/object that registers all its routes.

use actix_web::{get,Responder, App};

#[get("/user/hello")]
async fn index() -> impl Responder {
    "Hello"
}

#[get("/user/world")]
async fn world() -> impl Responder {
    "World"
}

pub fn home_router<T>(app: &App) -> &App
{
    app.service(index);
    return app;
}

However because AppEntry is not public in the module and App::new() returns App < AppEntry >. Also the where conditions for App are not generic so I can't build a generic method to make this work (that I know of).

I'm super new to Rust and curious if someone has any ideas how it could be possible to do something like this. Bonus points if you can add a prefix. I don't mind figuring it out if someone can lead this horse to water.

Chase R Lewis
  • 2,119
  • 1
  • 22
  • 47

0 Answers0