这是来自其主页的 actix_web 示例代码:
use actix_web::{web, App, Responder, HttpServer};
fn index(info: web::Path<(String, u32)>) -> impl Responder {
format!("Hello {}! id:{}", info.0, info.1)
}
fn main() -> std::io::Result<()> {
HttpServer::new(|| App::new().service(
web::resource("/{name}/{id}/index.html").to(index))
)
.bind("127.0.0.1:8080")?
.run()
}
我试图通过提取行的变量来重构代码web::resource...
:
use actix_web::{web, App, HttpServer, Responder};
fn index(info: web::Path<(u32, String)>) -> impl Responder {
format!("Hello {}! id:{}", info.1, info.0)
}
fn main() -> std::io::Result<()> {
let route = web::resource("/{id}/{name}/index.html").to(index);
HttpServer::new(|| App::new().service(route))
.bind("127.0.0.1:8080")?
.run()
}
但它编译失败。为什么失败了?以及如何在这里提取该变量?谢谢。