I'm building a web server using actix-web
. One of my endpoints tries to deserialize the incoming data into a form struct:
#[get("/tweets4")]
async fn tweets4(form: web::Form<TweetParams<'_>>) -> HttpResponse {
println!("{} {} {}", form.page, form.sort_by, form.timeframe);
HttpResponse::Ok().body("worked")
}
#[derive(serde::Deserialize, serde::Serialize, Debug)]
struct TweetParams<'a> {
page: &'a str,
sort_by: &'a str,
timeframe: &'a str,
}
The error I'm getting:
error: implementation of `_::_serde::Deserialize` is not general enough
--> src/main.rs:82:1
|
82 | #[get("/tweets4")]
| ^^^^^^^^^^^^^^^^^^ implementation of `_::_serde::Deserialize` is not general enough
|
= note: `TweetParams<'_>` must implement `_::_serde::Deserialize<'0>`, for any lifetime `'0`...
= note: ...but `TweetParams<'_>` actually implements `_::_serde::Deserialize<'1>`, for some specific lifetime `'1`
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
I'm pretty lost at deciphering the error and what it might mean. It sounds like the compiler isn't happy with Serde's out of the box Deserialize
implementation - but how do I fix it?
This error appeared when I switched to &str
from String
inside my struct.