gpt4 book ai didi

使用rust 柴油机 : the trait bound `NaiveDateTime: Deserialize<' _>` is not satisfied

转载 作者:行者123 更新时间:2023-12-03 11:25:56 25 4
gpt4 key购买 nike

我是使用rust 和柴油的新手。并尝试使用 Rocket 框架创建一个小型演示 api。
出现错误:特质绑定(bind)NaiveDateTime: Deserialize<'_>不满意
我用谷歌搜索并找到了一些有用的链接,例如:https://github.com/serde-rs/serde/issues/759
看起来版本有点问题。
这是我的文件:
架构.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
[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"]
型号.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
#[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!");
}
有人可以帮我吗?
谢谢 !

最佳答案

Chrono有一些optional features您必须启用它。
在这种情况下,您需要包含 serde作为 chrono 中的可选功能Cargo.toml 中的依赖项配置:

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

关于使用rust 柴油机 : the trait bound `NaiveDateTime: Deserialize<' _>` is not satisfied,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65378524/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com