Rust 如何在actix web中解析查询字符串?

Rust 如何在actix web中解析查询字符串?,rust,rust-actix,Rust,Rust Actix,如何使用以下URL解析name和color参数 http://example.com/path/to/page?name=ferret&color=purple 我假设我的路径应该是/path/to/page,然后当我尝试查询name时,我收到一个空字符串(req.match\u info().query(“name”)wherereq:&HttpRequest) 我唯一找到的是关于匹配名称(例如,如果路径是/people/{page}/,它将匹配/people/123/,这样page=123

如何使用以下URL解析
name
color
参数

http://example.com/path/to/page?name=ferret&color=purple
我假设我的路径应该是
/path/to/page
,然后当我尝试查询
name
时,我收到一个空字符串(
req.match\u info().query(“name”)
where
req:&HttpRequest

我唯一找到的是关于匹配名称(例如,如果路径是
/people/{page}/
,它将匹配
/people/123/
,这样
page=123
,但这不是我想要的

这是针对actix web v0.7的

我通过使用以下方法成功地使其工作:

let name = req.query().get("name").unwrap(); // name = "ferret"

看起来他们删除了
query
函数,只有一个
query\u string
函数。您可以使用一个称为:

还可以使用将查询参数反序列化为具有Serde的结构

use serde::Deserialize;

#[derive(Deserialize)]
struct Info {
    username: String,
}

fn index(info: web::Query<Info>) -> Result<String, actix_web::Error> {
    Ok(format!("Welcome {}!", info.username))
}
如果需要可选参数,只需在struct
选项中设置属性即可

username: Option<String>
username:选项

您还可以在处理程序中使用多个
web::Query
参数。

在最新版本中是否有此更改?在Actix web 1.0.7上,我收到
错误[E0599]:在当前范围内找不到类型
Actix\u web::request::HttpRequest
的名为
Query`的方法,这应该是可以接受的答案。
curl "http://localhost:5000"
curl "http://localhost:5000?password=blah"
username: Option<String>