如何将许多参数传递给 rust actix_web 路由

Pio*_*zek 13 rust actix-web

是否可以将多个参数传递到 axtic_web 路由中?

// srv.rs (frag.)

HttpServer::new(|| {
  App::new()
    .route(
      "/api/ext/{name}/set/config/{id}",
      web::get().to(api::router::setExtConfig),
    )
})
.start();
Run Code Online (Sandbox Code Playgroud)
// router.rs (frag.)

pub fn setExtConfig(
    name: web::Path<String>,
    id: web::Path<String>,
    _req: HttpRequest,
) -> HttpResponse {
  println!("{} {}", name, id);
  HttpResponse::Ok()
      .content_type("text/html")
      .body("OK")
}
Run Code Online (Sandbox Code Playgroud)

对于只有一个参数的路由,一切正常,但对于本示例,我在浏览器中仅看到消息:wrong number of parameters: 2 expected 1,响应状态代码为 404。

我确实需要传递更多参数(从一个到三个或四个)......

edw*_*rdw 11

这非常适合tuple

pub fn setExtConfig(
    param: web::Path<(String, String)>,
    _req: HttpRequest,
) -> HttpResponse {
    println!("{} {}", param.0, param.1);
    HttpResponse::Ok().content_type("text/html").body("OK")
}
Run Code Online (Sandbox Code Playgroud)