相关疑难解决方法(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
查看次数

mysql - 特性 `diesel::Expression` 没有为 `f64` 实现

我正在尝试使用柴油和 mysql 建立模型。我的第一个模型编译没有问题,但是当我的第二个模型(用于将新条目插入到我的数据库中的模型)尝试推导时,Insertable我收到了大量错误,指出diesel can't use f64, u16, 或NaiveDateTime

error[E0277]: the trait bound `u16: diesel::Expression` is not satisfied
  --> src/models.rs:26:10
   |
26 | #[derive(Insertable, Debug, Queryable)]
   |          ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `u16`
   |
   = note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Unsigned<diesel::sql_types::Integer>>` for `u16`
   = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `chrono::naive::datetime::NaiveDateTime: diesel::Expression` …
Run Code Online (Sandbox Code Playgroud)

mysql rust rust-diesel

5
推荐指数
1
解决办法
1166
查看次数

标签 统计

rust ×2

mysql ×1

rust-diesel ×1

serde ×1