我有一个异步响应器 impl,但是对象的生命周期有问题。编码:
#[rocket::async_trait]
impl<'r> Responder<'r, 'static> for LoginUser {
async fn respond_to(self, _: &'r Request) -> response::Result<'static> {
use LicensesStatus::*;
let status = self.check_licenses().await;
let json = serde_json::json!({"status": format!("{:?}", status)}).to_string();
let response = Response::build()
.sized_body(json.len(), Cursor::new(&json))
.header(ContentType::JSON);
match status {
Valid => response.ok(),
_ => response.status(Status::Conflict).ok()
}
}
}
编译错误:
error[E0195]: lifetime parameters or bounds on method `respond_to` do not match the trait declaration
--> src/views/login.rs:64:14
|
64 | async fn respond_to(self, _: &'r Request<'_>) -> response::Result<'static> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetimes do not match method in trait