简体   繁体   English

Rust Diesel:特征绑定 `NaiveDateTime: Deserialize<'_>` 不满足

[英]Rust Diesel: the trait bound `NaiveDateTime: Deserialize<'_>` is not satisfied

I am new to rust and diesel.我是 rust 和柴油的新手。 And trying to create a small demo api using rocket framework.并尝试使用火箭框架创建一个小型演示 api。
Getting error: the trait bound NaiveDateTime: Deserialize<'_> is not satisfied出现错误:特征绑定NaiveDateTime: Deserialize<'_>不满足

I googled and found some useful links like here: https://github.com/serde-rs/serde/issues/759我用谷歌搜索并找到了一些有用的链接,例如: https://github.com/serde-rs/serde/issues/759
It look like some problem with version.看起来版本有点问题。

Here are my files:这是我的文件:
schema.rs架构.rs

table! {
    department (dept_id) {
        dept_id -> Int4,
        dept_name -> Nullable<Text>,
        created_on -> Nullable<Timestamp>,
        created_by -> Nullable<Text>,
        modified_on -> Nullable<Timestamp>,
        modified_by -> Nullable<Text>,
        is_active -> Nullable<Bool>,
    }
}

cargo.toml货物.toml

[dependencies]
diesel = { version = "1.4.5", features = ["postgres","chrono","numeric"] }
dotenv = "0.15.0"
chrono = { version = "0.4.19" }
bigdecimal = { version = "0.1.0" }
rocket = "0.4.6"
rocket_codegen = "0.4.6"
r2d2-diesel = "1.0.0"
r2d2 = "0.8.9"
serde = { version = "1.0.118", features = ["derive"] }
serde_derive = "1.0.118"
serde_json = "1.0.60"

[dependencies.rocket_contrib]
version = "*"
default-features = false
features = ["json"]

model.rs model.rs

#![allow(unused)]
#![allow(clippy::all)]

use super::schema::department;
use serde::Serialize;
use serde::Deserialize;

use chrono::NaiveDateTime;
use bigdecimal::BigDecimal;
#[derive(Queryable, Debug, Identifiable, Serialize, Deserialize)]
#[primary_key(dept_id)]
#[table_name = "department"]
pub struct Department {
    pub dept_id: i32,
    pub dept_name: Option<String>,
    pub created_on: Option<NaiveDateTime>,
    pub created_by: Option<String>,
    pub modified_on: Option<NaiveDateTime>,
    pub modified_by: Option<String>,
    pub is_active: Option<bool>,
}

main.rs main.rs

#[macro_use]
extern crate diesel;
extern crate dotenv;
extern crate serde;
extern crate serde_derive;
extern crate serde_json;
extern crate chrono;
extern crate bigdecimal;

mod models;
mod schema;
mod connection;

fn main() {
    println!("Hello, Home!");
}

Can anybody help me on this?有人可以帮我吗?
Thanks !谢谢 !

You need to include serde feature in chrono in your Cargo.toml :您需要在chronoCargo.toml中包含serde功能:

chrono = { version = "0.4", features = ["serde"]}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Rust中不满足特征限制 - The trait bound is not satisfied in Rust 特性diesel::Expression 未为NaiveDate 实现,但它适用于NaiveDateTime - Trait diesel::Expression not implemented for NaiveDate, but it is for NaiveDateTime 特性绑定 `&'a chain::Chain<'a>: Deserialize<'_>` 不满足 - the trait bound `&'a chain::Chain<'a>: Deserialize<'_>` is not satisfied 特征绑定`chrono::DateTime<utc> : 来自Sql <diesel::sql_types::nullable<diesel::sql_types::timestamptz> ,pg&gt;`不满足</diesel::sql_types::nullable<diesel::sql_types::timestamptz></utc> - Trait bound `chrono::DateTime<Utc>: FromSql<diesel::sql_types::Nullable<diesel::sql_types::Timestamptz>, Pg>` is not satisfied Rust: Error[E0277]: trait bound `{integer}: SampleRange&lt;_&gt;` 不满足 - Rust: Error[E0277]: the trait bound `{integer}: SampleRange<_>` is not satisfied 编译器说:特征绑定 `Foo: serde::de::Deserialize` 不满足 - 当它满足时 - Compiler says: the trait bound `Foo: serde::de::Deserialize` is not satisfied - when it is Rust 特征不满足 - Rust trait not satisfied rust 柴油方法“过滤器”存在于模式表,但其特征界限不满足? - rust diesel method `filter` exists for schema table, but its trait bounds were not satisfied? 特质界限不满足 - The trait bound is not satisfied 无法在 rust 柴油机中使用通用参数实现特征 - Cannot implement trait with generic param in rust diesel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM