我正在使用 Rust 和 HTTP 开发自助门户。但是,我在导入 Server 时遇到以下错误 我正在使用依赖项的完整功能。我尝试了很多方法来导入,例如
use hyper::{Body, Request, Response, Server};
但没有运气
use hyper::server::Server;
| ^^^^^^^^^^^^^^^^^^^^^ no `Server` in `server`
这里是依赖
hyper = { version = "^1.0.1", features = ["full"]}
serde = { version = "^1.0.203", features = ["derive"] }
serde_derive = "^1.0.203"
serde_json = { version = "^1.0.133", features = ["raw_value"] }
serde_with = { version = "^3.8.2", features = ["chrono"] }
这是我的main.rs
use axum::{
extract::Form,
response::{Html, Redirect},
routing::{get, post},
Router,
Extension,
};
use hyper::server::Server;
use serde::Deserialize;
use std::net::SocketAddr;
use tera::{Context, Tera};
#[derive(Deserialize)]
struct CreateDagForm {
dag_name: String,
schedule: String,
}
async fn show_base(Extension(tera): Extension<Tera>) -> Html<String> {
let rendered = tera.render("base.html", &Context::new()).unwrap();
Html(rendered)
}
async fn create_dag(Form(form): Form<CreateDagForm>) -> Redirect {
println!("Received DAG: Name = {}, Schedule = {}", form.dag_name, form.schedule);
Redirect::to("/")
}
#[tokio::main]
async fn main() {
let tera = Tera::new("templates/**/*").expect("Failed to initialize Tera");
let app = Router::new()
.route("/", get(show_base))
.route("/create_dag", post(create_dag))
.layer(Extension(tera));
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("Server running at http://{}", addr);
Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
}
我尝试了很多方法,如下所示
let Server = hyper::server::Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
但我遇到了同样的错误
unresolved import `hyper::server::Server`
--> src/main.rs:8:5
|
8 | use hyper::server::Server;
| ^^^^^^^^^^^^^^^^^^^^^ no `Server` in `server`
中没有
Server
类型。 具有该类型的最后一个版本是 0.14.32,但您请求至少 1.0.1。
一些建议: