【发布时间】:2020-06-04 03:37:18
【问题描述】:
在Actix Web Framework中,如何使用路由属性宏(#[http_method("route")])将多个http方法绑定到一个函数?
例如,我有这个微不足道的端点:
/// Returns a UUID4.
#[get("/uuid")]
async fn uuid_v4() -> impl Responder {
HttpResponse::Ok().json(Uuid {
uuid: uuid::Uuid::new_v4(),
})
}
我想让相同的端点处理 HEAD 请求,我该怎么做?
我最初的方法是堆叠宏:
/// Returns a UUID4.
#[get("/uuid")]
#[head("/uuid")]
async fn uuid_v4() -> impl Responder {
HttpResponse::Ok().json(Uuid {
uuid: uuid::Uuid::new_v4(),
})
}
但我确实收到了编译错误:
|
249 | async fn uuid_v4() -> impl Responder {
| ^^^^^^^ the trait `actix_web::handler::Factory<_, _, _>` is not implemented for `<uuid_v4 as actix_web::service::HttpServiceFactory>::register::uuid_v4`
我浏览了actix-web 和actix-web-codegen docs 并没有找到任何解决这个问题的方法
【问题讨论】:
标签: rust rust-actix actix-web