我正在尝试使用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) 我正在尝试使用柴油和 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)