Rust 如何在actix web中使用tokio_postgres
所以我想在actix API中使用tokio_postgres,我刚刚开始,在get请求中共享客户端时遇到了困难。 这是我的密码:Rust 如何在actix web中使用tokio_postgres,rust,actix-web,Rust,Actix Web,所以我想在actix API中使用tokio_postgres,我刚刚开始,在get请求中共享客户端时遇到了困难。 这是我的密码: use actix_web::{web, App, HttpServer, HttpResponse}; use tokio_postgres::{NoTls}; use std::cell::RefCell; mod api; use api::routes::hello_actix; fn main() { actix_rt::System::ru
use actix_web::{web, App, HttpServer, HttpResponse};
use tokio_postgres::{NoTls};
use std::cell::RefCell;
mod api;
use api::routes::hello_actix;
fn main() {
actix_rt::System::run(|| {
println!("connecting to postgres");
let pro = tokio::spawn(
async
{
let (client , conn) = match tokio_postgres::connect(
"foo",
NoTls)
.await {
Ok(t) => t,
Err(e) => panic!("{}", e)
};
tokio::spawn(async move {
if let Err(e) = conn.await {
eprintln!("connection error: {}", e);
}
});
println!("connected to postgres");
HttpServer::new(|| {
App::new()
.data(RefCell::new(conn))
.route("/hello", web::get().to(hello_actix))
.default_service(web::route().to(|| HttpResponse::NotFound().body("404 Not Found")))
})
.bind("127.0.0.1:8080")
.unwrap()
.run();
Ok(())
});
});
}
我基于此代码,但它似乎不起作用
我还想保持“纯”,所以如果可能的话,我不想拥有全球客户。
甚至可以做我想做的事吗