关于`Deserialize`的编译器投诉未派生

时间:2017-06-09 07:36:58

标签: rust iron

我一直试图让bodyparseriron工作。到目前为止,这是我的结构:

#[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,所以我不知道这里有什么问题。可以找到完整的来源here

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

0 个答案:

没有答案