ted*_*ner -1 rust rust-cargo rust-chrono rust-diesel
我正在尝试用作chrono::NaiveDate数据库模型字段。这是模型:
use chrono::{NaiveDate, NaiveDateTime};\nuse diesel::{Insertable, Queryable};\nuse serde::{Deserialize, Serialize};\n\nuse crate::schema::users;\n\n#[derive(Debug, Serialize, Deserialize, Associations, Identifiable, Queryable)]\n#[table_name = "users"]\npub struct User {\n pub id: uuid::Uuid,\n pub password_hash: String,\n pub is_active: bool,\n\n pub is_premium: bool,\n pub premium_expiration: Option<NaiveDate>,\n\n pub email: String,\n pub first_name: String,\n pub last_name: String,\n pub date_of_birth: NaiveDate,\n pub currency: String,\n\n pub modified_timestamp: NaiveDateTime,\n pub created_timestamp: NaiveDateTime,\n}\n\n#[derive(Debug, Insertable)]\n#[table_name = "users"]\npub struct NewUser<'a> {\n pub id: uuid::Uuid,\n pub password_hash: &'a str,\n pub is_active: bool,\n\n pub is_premium: bool,\n pub premium_expiration: Option<NaiveDate>,\n\n pub email: &'a str,\n pub first_name: &'a str,\n pub last_name: &'a str,\n pub date_of_birth: NaiveDate,\n pub currency: &'a str,\n\n pub modified_timestamp: NaiveDateTime,\n pub created_timestamp: NaiveDateTime,\n}\nRun Code Online (Sandbox Code Playgroud)\n当我运行时cargo check,我从 rustc 收到以下错误:
error[E0277]: the trait bound `NaiveDate: diesel::Expression` is not satisfied\n --> src/models/user.rs:27:17\n |\n27 | #[derive(Debug, Insertable)]\n | ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `NaiveDate`\n |\n = note: required because of the requirements on the impl of `AsExpression<diesel::sql_types::Nullable<diesel::sql_types::Timestamp>>` for `NaiveDate`\n = note: this error originates in the derive macro `Insertable` (in Nightly builds, run with -Z macro-backtrace for more info)\n\nerror[E0277]: the trait bound `NaiveDate: diesel::Expression` is not satisfied\n --> src/models/user.rs:27:17\n |\n27 | #[derive(Debug, Insertable)]\n | ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `NaiveDate`\n |\n = note: required because of the requirements on the impl of `diesel::Expression` for `&'insert NaiveDate`\n = note: required because of the requirements on the impl of `AsExpression<diesel::sql_types::Nullable<diesel::sql_types::Timestamp>>` for `&'insert NaiveDate`\n = note: this error originates in the derive macro `Insertable` (in Nightly builds, run with -Z macro-backtrace for more info)\n\nerror[E0277]: the trait bound `NaiveDate: diesel::Expression` is not satisfied\n --> src/models/user.rs:27:17\n |\n27 | #[derive(Debug, Insertable)]\n | ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `NaiveDate`\n |\n = note: required because of the requirements on the impl of `diesel::Expression` for `&NaiveDate`\n = note: required because of the requirements on the impl of `AsExpression<diesel::sql_types::Nullable<diesel::sql_types::Timestamp>>` for `&NaiveDate`\n = note: this error originates in the derive macro `Insertable` (in Nightly builds, run with -Z macro-backtrace for more info)\n\nFor more information about this error, try `rustc --explain E0277`.\nRun Code Online (Sandbox Code Playgroud)\n我的相关行Cargo.toml:
[dependencies]\nchrono = { version = "0.4", features = ["serde"] }\ndiesel = { version = "1.4", features = ["postgres", "uuidv07", "r2d2", "chrono"] }\nRun Code Online (Sandbox Code Playgroud)\n运行cargo tree | grep chrono给出以下输出,表明与 不存在版本冲突chrono:
\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 chrono v0.4.19\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 chrono v0.4.19 (*)\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 chrono v0.4.19 (*)\nRun Code Online (Sandbox Code Playgroud)\n我NaiveDate以前曾在柴油模型中使用过,并且在导出宏时没有任何问题Insertable。我在这里缺少什么阻止宏实现diesel::Expressionforchono::NaiveDate而它似乎已实现chono::NaiveDateTime?