Methods 带扭曲的根路径示例?

Methods 带扭曲的根路径示例?,methods,rust,routes,closures,rust-warp,Methods,Rust,Routes,Closures,Rust Warp,这是新手入门的rust warp示例。这本应该是“超级简单”,但现在却让我觉得自己超级愚蠢 使用warp::Filter; #[tokio::main] 异步fn main(){ //GET/hello/warp=>200 OK,正文为“hello,warp!” 让hello=warp::path!(“hello”/String) .map(| name | format!(“你好,{}!”,name)); warp::serve(你好) .运行([127,0,0,1],3030)) .等待;

这是新手入门的rust warp示例。这本应该是“超级简单”,但现在却让我觉得自己超级愚蠢

使用warp::Filter;
#[tokio::main]
异步fn main(){
//GET/hello/warp=>200 OK,正文为“hello,warp!”
让hello=warp::path!(“hello”/String)
.map(| name | format!(“你好,{}!”,name));
warp::serve(你好)
.运行([127,0,0,1],3030))
.等待;
}
我想在根路径上运行它,定义如下:

让hello=warp::path!(“”/).map(| |“你好!”);
但是宏不采用空路径名。我得到一个错误:

no rules expected the token `start`
我猜“超级容易”对不同的人意味着不同的东西

附录:

因此,我尝试了Ivan C(下面的评论)提到的解决方案,但它也不起作用。应用

let hello=warp::path::end().map(| name | format!(“hello”);
依次导致此错误消息:

[rustc E0599][E]在当前作用域中找不到不透明类型`impl warp::Filter+std::marker::Copy`的名为`map`的方法
在'impl warp::Filter+std::marker::Copy'中找不到方法`
注意:方法“map”存在,但以下特征边界不存在
满足:`impl-warp::Filter+std::marker::Copy:std::iter::Iterator`
似乎只有在不需要根路由的情况下,使用扭曲路径的路由才有效,根路由只是一个显示阻止器。

这不编译:

let hello=warp::path::end()
.map(| name | format!(“Hello”);
因为如果您不再在路由路径的任何部分上进行动态匹配,那么闭包中的
name
参数将从何而来?如果删除未使用的
名称
参数和
格式也是不必要的,那么它可以工作:

使用warp::Filter;
#[tokio::main]
异步fn main(){
让hello=warp::path::end()
.map(| |“你好”);
warp::serve(你好)
.运行([127,0,0,1],3030))
.等待;
}

访问
http://127.0.0.1:3030
现在生成
你好

试试路径!没有参数的宏。我真丢脸:-(