以下两个“hello world”示例均成功构建,但只有第一个结果显示为“Hello World”的页面;第二个给我一个关于找不到页面的错误。两者的 Cargo.toml 文件是相同的。我正在访问 IP 127.0.0.1:3030
。
我尝试使用 curl 访问第二个,但它什么也没返回并返回到提示符。我第一个成功使用的浏览器是 Microsoft Edge 84。
为什么第二个不起作用?
第一
#![deny(warnings)]
use warp::Filter;
#[tokio::main]
async fn main() {
// Match any request and return hello world!
let routes = warp::any().map(|| "Hello, World!");
warp::serve(routes).run(([127, 0, 0, 1], 3030)).await;
第二个
use warp::Filter;
#[tokio::main]
async fn main() {
// GET /hello/warp => 200 OK with body "Hello, warp!"
let hello = warp::path!("hello" / String)
.map(|name| format!("Hello, {}!", name));
warp::serve(hello)
.run(([127, 0, 0, 1], 3030))
.await;
}
货运.toml
[package]
name = "warptest"
version = "0.1.0"
authors = ["user"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tokio = { version = "0.2", features = ["full"] }
warp = "0.2"