What should the return type be for hyper service?

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    let addr = ([127, 0, 0, 1], 3000).into();

    let service = make_service_fn(|_| {
        async {
            Ok::<_, hyper::Error>(service_fn(echo))
        }
    });

    let server = Server::bind(&addr)
        .serve(service);

    println!("Listening on http://{}", addr);

    server.await?;

    Ok(())
}

This starts an echo server taken from hyper repo https://github.com/hyperium/hyper/blob/master/examples/echo.rs

I would like to refacator it to create serve method like

fn serve() -> ReturnType {
let addr = ([127, 0, 0, 1], 3000).into();

let service = make_service_fn(|_| {
    async {
        Ok::<_, hyper::Error>(service_fn(echo))
    }
});

return service;

}

But i don't know what the return type should be.

The return type is MakeServiceFn<F>, which is not publicly exposed from Hyper. So you can't do this, I'm afraid.

You could, however, extract out the thing you pass in to make_service_fn - the type of that is a FnMut closure/function that takes a &Ctx and returns impl IntoFuture.

I am afraid I don't how to do that. I am new to Rust.

Can you please show me an example?