How to join! with axum::serve::Serve future?

I just started to learn rust :slight_smile: and working on a small web service application based on axum.

I'm working with future for the synchronous implementation and get a Serve<Router,Router> object which is the Future according to the documentation: Serve in axum::serve - Rust

Unfortunately the compiler doesn't accept this future within the join! macro:

Serve<Router, Router> is not a future

Here is a minimal example:

async fn hello() -> String {
    return "hello".to_string()

async fn world() -> String {
    return "world".to_string()

async fn main() -> std::io::Result<()> {
    println!("Hello, world!");

    let a = axum::serve(
        Router::new().route("/hello", get( hello))

    let b = axum::serve(
        Router::new().route("/world", get( world))


    tokio::join!(a, b);


Does anyone has a hint, what I'm doing wrong? And what I'm misunderstanding in the documentation where axum::serve::Serve is described as the Future...?


I think you have to call Serve::into_future to convert it to a type that implements Future.

Edit: indeed, it compiles. But probably even better is to spawn a task for each server.

Hi @jofas

Wow, many thanks for the answer. As well as for the idea of using spawn. That feels pretty good!

And is also new for me. That's really nice to share a minimal working example :slight_smile:

Thanks for all that good stuff and merry Christmas

1 Like

Merry Christmas to you as well :slightly_smiling_face:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.