Could Axum Router work without Send?

I'm testing Axum with the tokio current runtime, I wanted to see if I could simplify some other parts of my app, no need for Arc and my traits wouldn't need to implement Send, which isn't a huge deal so far, but I wanted to see if I could. But sadly, I can't pass state around because the Router implementation requires state to implement Send.

Is that really necessary to the way the router works ? Or maybe did I misunderstand what the current runtime actually is ?

I think that limitation comes from Axum using the multi-threaded Tokio runtime by default. If you don't want that behaviour, you could perhaps run it with the single-threaded runtime:

#[tokio::main(flavor = "current_thread")]
async fn main() {
    // Axum code here...
}

That's what I did, it works, but the only implementation of the Router is still Send so you are forced to use Arc and Send regardless.

You can do this by making your own version of axum::serve. I think you can just replace spawn with spawn_local to get rid of Send. That still requires 'static, so you would replace Arc with Rc. If you wanted to get rid of Rc, you could manage it with some FuturesUnordered and creating the state outside the runtime.

Edit: seems like to get rid of 'static you'd need to also redo a bunch of hyper stuff since hyper requires 'static: Builder in hyper_util::server::conn::auto - Rust And I forgot to mention you need to also wrap your stuff in a LocalSet to use spawn_local.