2

我一直在努力bodyparser工作iron。到目前为止,这是我的结构:

#[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
}

但是编译器在这里给了我一个错误:

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>`

但是我#[derive(Deserialize)]在那里用过struct,所以我不知道这里出了什么问题。完整的源代码可以在这里找到。

我的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"
4

0 回答 0