- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试创建一个可以在 diesel 中用于插入的结构。具体来说,我正在使结构可插入。编译时出现此错误。
我有一个结构,我正试图通过 derive 属性使 Insertable
成为可能。我有一个名为 Bounty
的字段,它应该代表钱,所以我使用 BigDecimal
作为类型。编译后,我得到标题中的错误。我也尝试过使用 f64
但它给出了同样的错误。
#[macro_use]
extern crate diesel;
extern crate bigdecimal;
mod schema {
use bigdecimal::BigDecimal;
table! {
Threads (Id) {
Id -> Int8,
Views -> Int4,
Points -> Int4,
FlagPoints -> Int4,
IsDisabled -> Bool,
IsAnswered -> Bool,
Bounty -> Numeric,
Title -> Varchar,
Body -> Text,
UserId -> Int8,
CreatedBy -> Varchar,
CreatedOn -> Timestamptz,
LastModifiedBy -> Varchar,
LastModifiedOn -> Timestamptz,
}
}
#[allow(non_snake_case)]
#[derive(Debug, Insertable)]
#[table_name = "Threads"]
pub struct InsertableThread {
pub Bounty: BigDecimal,
pub Title: String,
pub Body: String,
pub UserId: i64
}
}
fn main() {}
我的结构在它自己的文件中,这是完整的代码。 struct Thread
编译没有问题。错误发生在 InsertableThread
上,因为它是使用 BigDecimal
的线程。这是导致的错误。
error[E0277]: the trait bound `bigdecimal::BigDecimal: diesel::Expression` is not satisfied
--> src/main.rs:29:21
|
29 | #[derive(Debug, Insertable)]
| ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `bigdecimal::BigDecimal`
|
= note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Numeric>` for `bigdecimal::BigDecimal`
error[E0277]: the trait bound `bigdecimal::BigDecimal: diesel::Expression` is not satisfied
--> src/main.rs:29:21
|
29 | #[derive(Debug, Insertable)]
| ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `bigdecimal::BigDecimal`
|
= note: required because of the requirements on the impl of `diesel::Expression` for `&bigdecimal::BigDecimal`
= note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Numeric>` for `&bigdecimal::BigDecimal`
error[E0277]: the trait bound `bigdecimal::BigDecimal: diesel::Expression` is not satisfied
--> src/main.rs:29:21
|
29 | #[derive(Debug, Insertable)]
| ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `bigdecimal::BigDecimal`
|
= note: required because of the requirements on the impl of `diesel::Expression` for `&'insert bigdecimal::BigDecimal`
= note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Numeric>` for `&'insert bigdecimal::BigDecimal`
我正在使用 Rust 1.34、diesel 1.4.2 和 Postgres 11。
我愿意更改数据库、Postgres 或 Rust 代码中的类型。数据库使用 numeric
,在 Rust 代码中我尝试了 f64
和 BigDecimal
。我也愿意自己直接实现该特征,但由于找不到示例,我需要有关如何实现的一些指导。
最佳答案
柴油使用 Cargo features选择加入增强功能。
我还没有找到这些的明确文档页面,但它们列在 its Cargo.toml 中:
[features]
default = ["with-deprecated", "32-column-tables"]
extras = ["chrono", "serde_json", "uuid", "deprecated-time", "network-address", "numeric", "r2d2"]
unstable = ["diesel_derives/nightly"]
large-tables = ["32-column-tables"]
huge-tables = ["64-column-tables"]
x32-column-tables = ["32-column-tables"]
32-column-tables = []
x64-column-tables = ["64-column-tables"]
64-column-tables = ["32-column-tables"]
x128-column-tables = ["128-column-tables"]
128-column-tables = ["64-column-tables"]
postgres = ["pq-sys", "bitflags", "diesel_derives/postgres"]
sqlite = ["libsqlite3-sys", "diesel_derives/sqlite"]
mysql = ["mysqlclient-sys", "url", "diesel_derives/mysql"]
with-deprecated = []
deprecated-time = ["time"]
network-address = ["ipnetwork", "libc"]
numeric = ["num-bigint", "bigdecimal", "num-traits", "num-integer"]
您需要启用numeric 功能并确保您使用与 Diesel 兼容的 bigdecimal 版本:
[dependencies]
diesel = { version = "1.4.2", features = ["numeric"] }
bigdecimal = "0.0.14"
然后代码编译:
#[macro_use]
extern crate diesel;
use crate::schema::threads;
use bigdecimal::BigDecimal;
mod schema {
table! {
threads (id) {
id -> Int4,
bounty -> Numeric,
}
}
}
#[derive(Debug, Insertable)]
#[table_name = "threads"]
pub struct InsertableThread {
pub bounty: BigDecimal,
}
另见:
关于postgresql - 特性 `diesel::Expression` 没有为 `bigdecimal::BigDecimal` 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55783064/
当你做这样的事情 BigDecimal bigDecimal = BigDecimal.ONE; 为什么bigDecimal成为一个新对象? 最佳答案 在这种情况下,变量(或字段)bigDecimal
我正在使用 BigDecimal 计算一些大实数。虽然我尝试了两种方法:BigDecimal.toString() 或 BigDecimal.stripTrailingZeros().toString
我广泛使用 BigDecimals。我经常需要进行长时间的计算,然后比较结果。由于这些漫长的计算,答案不是 1而是0.9999999... 。这就是为什么我无法精确比较 BigDecimals,而只能
我有一段代码有两个 BigDecimal 变量。这两个变量都被发送到方法格式(工作正常)然后打印。变量“d”被发送到格式方法,然后直接打印而不分配它(因为格式方法返回一个字符串)。问题出现在变量 a
我遇到过 java.math.BigDecimal 和 android.icu.math.BigDecimal 因为我需要在项目中使用 BigDecimal . 我意识到 Android BigDec
我在整个应用程序中使用 BigDecimal 来处理金钱 和百分比。但是,我需要一种方法来区分两者之间的用法(为了呈现它们,即在 JTable 中)。因此,我最初的想法是编写两个行为与 BigDeci
这应该很简单,但它正在爆炸。有什么想法吗? d = BigDecimal.new("2.0") YAML::load({:a => d}.to_yaml) TypeError: BigDecimal
我有两个 BigDecimal,我想根据它们的 significant digits 确定它们是否接近。 . 例如,请考虑以下内容: BigDecimal million = new BigDecim
我需要一种方法将其表达为有效的java代码:我有2个BigDecimals,我想知道较小的BigDecimal是否可以(当添加到较大的BigDecimals时) BigDecimal 一次)更改较大
我正在争论是使用 BigDecimal 和 BigInteger 还是仅使用 BigDecimal 来让我的生活更轻松,减少来回转换。在资源方面仅使用 BigDecimal 有缺点吗? 仅使用原始数据
我有以下代码: Welcome to Scala version 2.10.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_45). scala> v
我有一个 java 客户端,它通过 GRPC 调用 Clojure 服务。问题是,当我们从他们的服务收到响应时,它会在大十进制的末尾添加字母。当我们尝试在 java 中将其转换为大十进制时,我们会收到
我仍在学习 Java,并且一直在阅读多个站点上的文章。我在 Java Code Geeks 找到了一篇文章我有一个问题。该文章正在解释开放/封闭原则。本文以对公司产品应用折扣的场景为例。第一部分代码如
我正在尝试对 List 中的多个 BigDecimals 求和.目前,我正在使用两个流,但如果可能的话,我希望只有一个流。我不确定如何以高效的方式重写下面的内容。 BigDecimal totalCh
下面两行代码有什么区别? BigDecimal one = new BigDecimal("1"); BigDecimal two = BigDecimal.ONE; 两条线是否相同? 谢谢! 最佳答
这个问题在这里已经有了答案: BigDecimal from Double incorrect value? (4 个答案) Convert double to BigDecimal and set
在 Java 中,来自另一个 bigDecimal.toString() 的新 BigDecimal 是否总是等于?例如 BigDecimal a = new BigDecimal("1.23
对于新变量的比较或初始化,您使用其中的哪一个会有所不同吗? 我知道 BigDecimal.ZERO 是 1.5 的功能,所以这是一个问题,但假设我使用的是 1.5,这有关系吗? 谢谢。 最佳答案 Bi
情况: public static double pi(int a) { return (BigDecimal.valueOf(53360*sqrt(640320))).divide(co
我正在尝试创建一个可以在 diesel 中用于插入的结构。具体来说,我正在使结构可插入。编译时出现此错误。 我有一个结构,我正试图通过 derive 属性使 Insertable 成为可能。我有一个名
我是一名优秀的程序员,十分优秀!