2

I have been trying to get bodyparser and iron to work. This is my structure so far:

#[macro_use]
extern crate serde_derive;
extern crate iron;
extern crate serde;
extern crate bodyparser;

#[derive(Serialize, Deserialize, Clone, Debug)]
struct UserLogin {
    email: String,
    password: String,
}

fn login(req: &mut Request) -> IronResult<Response> {
    let user : UserLogin = match req.get::<bodyparser::Struct<UserLogin>>() {
        Ok(Some(body)) => body,
        _ => return internal_error("Malformed body")
    };
    // Omitted for brevity
}

But the compiler gives me an error here:

error[E0277]: the trait bound `routes::UserLogin: serde::de::Deserialize` is not satisfied
   --> src/routes/mod.rs:130:38
    |
130 |     let user : UserLogin = match req.get::<bodyparser::Struct<UserLogin>>() {
    |                                      ^^^ the trait `serde::de::Deserialize` is not implemented for `routes::UserLogin`
    |
    = note: required because of the requirements on the impl of `iron::typemap::Key` for `bodyparser::Struct<routes::UserLogin>`

But I used #[derive(Deserialize)] up there on the struct, so I don't know what's wrong here. Full source can be found here.

My Cargo.toml:

[dependencies]
bodyparser = "0.5"
bson = "0.8"
iron = "0.5"
jwt = "0.4"
mongodb = "0.3"
router = "0.5"
rust-crypto = "0.2"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
time = "0.1"
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Lanbo
  • 15,118
  • 16
  • 70
  • 147

0 Answers0