- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是使用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/
我正在尝试在具有相同特征的盒装特征对象上实现特征。我以前对其方法采用的特征做过这样的事情&Self,它工作得很好,但不是Self。。我意识到在这个特定的例子中,我可以将fn get_*()函数更改为返
在编写带有特征的代码时,您可以将特征放在特征边界中: use std::fmt::Debug; fn myfunction1(v: Box) { println!("{:?}", v); }
我有一个特征正在使用另一个特征,现在我收到关于类中不存在的函数的错误。我简化了代码: 设置.php: getMessage());} } } ?> 数据库.php pdo=new PDO("m
这个问题在这里已经有了答案: Why doesn't Rust support trait object upcasting? (4 个回答) 2年前关闭。 如果我有 Box , 我可以返回 &dyn
给定这段代码: trait Trait {} struct Child; impl Trait for Child {} struct Father { child: &'a Box, } i
这个问题的标题与许多相关问题非常相似,但我还没有找到一个讨论这个特定问题的问题。 我有一个 Color非常简单定义的类型,如下所示: pub struct Color { red: u8,
我有三个特点。 Trait Param、GroupId 和 SessionId。特征 GroupId 和 SessionId 包括 Param。 类 GroupSession 包括特征 GroupId
查看 Traversable 和 TraversableLike 的 scaladoc,我很难弄清楚它们之间的区别是什么(除了一个扩展另一个)。文档中唯一明显的区别是它说 Traversable 是一
我有以下代码: trait T { type AT; fn foo(&self); } struct AbstractT { t: Box>, } impl T for Abs
如何在 Rust 中尝试类似以下的操作? builder 类是一个 trait 对象,它返回另一个 trait 对象(类型删除),其中选择的实现由我们正在使用的 builder trait 的特定对象
我想创建一个新向量,其中包含实现 Trait 的对象,来 self 已有的包含这些对象的一些向量。 trait Foo { // } struct Bar { i: i32, } st
到目前为止,在我的项目中,我使用了许多特征来允许在单元测试中模拟/ stub 以注入(inject)依赖项。然而,到目前为止我正在做的事情的一个细节似乎非常可疑,以至于我很惊讶它甚至可以编译。我担心正
假设我有一些特质: trait MyTrait { fn function1(&self); } 和一些实现它的类型: struct MyStruct { number: i32, }
更新:不止我一个人在思考这个问题,看来这确实是一个错误。参见 here .修复的那一天将是美好的一天! :) 这开始为 I love PHP traits! I'm going to use them
以下特征Parser[+T]是扩展接受 Input 的函数的特征并返回 Result[T] . trait Parser[+T] extends (Input => Result[T]) 那是对的吗
我有一个类型,我可以通过它访问它的方法 SomeTrait::::method() 但我不明白那和之间的区别 >::method() 在 C++ 中,我希望这样: SomeTrait::method(
在下面的代码中,不可能从对实现相同特征的动态大小类型的引用中获得对特征对象的引用。为什么会这样呢?如果我可以同时调用trait方法,那么&dyn Trait和&(?Sized + Trait)之间到底
我是 Rust 的新手,我想通过实现一些小项目来学习这门语言并更好地理解。我的第一次尝试是解析从 MQTT 代理收到的 JSON 数据。 我很高兴在 tornado 的帮助下轻松完成这项工作。和 se
在下面的代码中,不可能从对实现相同特征的动态大小类型的引用中获得对特征对象的引用。为什么会这样呢?如果我可以同时调用trait方法,那么&dyn Trait和&(?Sized + Trait)之间到底
这个问题在这里已经有了答案: Why is the `Sized` bound necessary in this trait? (2 个回答) 1年前关闭。 我有一个特质 Vertex我想要几个结构
我是一名优秀的程序员,十分优秀!