0

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.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
ilmoi
  • 1,994
  • 2
  • 21
  • 45
  • It's hard to answer multiple questions made in one post. I've removed the second question to allow answerers to focus on just the one. If you still have the other question, you should post a separate question. – Shepmaster Jun 01 '21 at 14:29
  • It looks like your question might be answered by the answers of [How do I resolve “implementation of serde::Deserialize is not general enough” with actix-web's Json type?](https://stackoverflow.com/q/57976096/155423). If not, please **[edit]** your question to explain the differences. Otherwise, we can mark this question as already answered. – Shepmaster Jun 01 '21 at 14:41
  • Thanks a ton @Shepmaster, that question does indeed answer my own. My bad for failing to find it. – ilmoi Jun 01 '21 at 16:20

0 Answers0