I wish to resolve the following code, but Rust panics because the actix future server() does not implement the trait Send. I didn't find a way to paralelize the actix server whithout error.
use tokio::runtime::Runtime;
use actix_web::{get, App, HttpResponse, HttpServer, Responder};
fn main() {
let rt = Runtime::new().unwrap();
let handle = rt.spawn(server());
rt.block_on(handle).unwrap();
// other activities in paralell with the server, is a crypto bot
// and the server is for view the behavior
}
#[get("/")]
async fn hello_world() -> impl Responder {
HttpResponse::Ok().body("Hello world!")
}
async fn server() -> Result<(), std::io::Error> {
HttpServer::new(|| {
App::new().service(hello_world)
})
.bind(("127.0.0.1", 5000))?
.run()
.await
}
the relevant panic info is the following:
error: future cannot be sent between threads safely
--> src/main.rs:7:27
|
7 | let handle = rt.spawn(server());
| ^^^^^^^^ future returned by `server` is not `Send`
|
= help: within `impl std::future::Future<Output = Result<(), std::io::Error>>`, the trait `Send` is not implemented for `Rc<[Box<dyn Fn() -> Pin<Box<dyn Future<Output = ...>>>>]>`
note: future is not `Send` as this value is used across an await