相关疑难解决方法(0)

为什么没有实现明确实现它的类型的特征?

我正在尝试使用Diesel查询MySQL数据库并使用带有Rocket的Handlebars模板显示结果.

我在models.rs中有这个

#[derive(Queryable, Serialize)]
pub struct Post {
    pub id: i32,
    pub title: String,
    pub text: String,
    pub published: bool,
}
Run Code Online (Sandbox Code Playgroud)

cargo run 输出:

  --> src/main.rs:69:5
   |
69 |     Template::render("index", &results)
   |     ^^^^^^^^^^^^^^^^ the trait `serde::ser::Serialize` is not implemented for `tasty::models::Post`
   |
   = note: required because of the requirements on the impl of `serde::ser::Serialize` for `std::vec::Vec<tasty::models::Post>`
   = note: required by `rocket_contrib::Template::render`
Run Code Online (Sandbox Code Playgroud)

在我的Cargo.toml中,我有这个:

[dependencies]
chrono = "0.3.0"
rocket = "0.2.8"
rocket_codegen = "0.2.8"
serde = …
Run Code Online (Sandbox Code Playgroud)

rust serde

9
推荐指数
1
解决办法
1994
查看次数

标签 统计

rust ×1

serde ×1