Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mysql-没有为'f64'实现特性'diesel::Expression'`_Mysql_Rust_Rust Diesel - Fatal编程技术网

mysql-没有为'f64'实现特性'diesel::Expression'`

mysql-没有为'f64'实现特性'diesel::Expression'`,mysql,rust,rust-diesel,Mysql,Rust,Rust Diesel,我正在尝试使用diesel和mysql建立一个模型。我的第一个模型编译时没有问题,但当我的第二个模型(用于向我的数据库插入新条目的模型)尝试派生Insertable时,我收到一系列错误,说明diesel不能使用f64、u16或NaiveDateTime error[E0277]: the trait bound `u16: diesel::Expression` is not satisfied --> src/models.rs:26:10 | 26 | #[derive(In

我正在尝试使用diesel和mysql建立一个模型。我的第一个模型编译时没有问题,但当我的第二个模型(用于向我的数据库插入新条目的模型)尝试派生
Insertable
时,我收到一系列错误,说明diesel不能使用
f64
u16
NaiveDateTime

error[E0277]: the trait bound `u16: diesel::Expression` is not satisfied
  --> src/models.rs:26:10
   |
26 | #[derive(Insertable, Debug, Queryable)]
   |          ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `u16`
   |
   = note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Unsigned<diesel::sql_types::Integer>>` for `u16`
   = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `chrono::naive::datetime::NaiveDateTime: diesel::Expression` is not satisfied
  --> src/models.rs:26:10
   |
26 | #[derive(Insertable, Debug, Queryable)]
   |          ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `chrono::naive::datetime::NaiveDateTime`
   |
   = note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Date>` for `chrono::naive::datetime::NaiveDateTime`
   = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `f64: diesel::Expression` is not satisfied
  --> src/models.rs:26:10
   |
26 | #[derive(Insertable, Debug, Queryable)]
   |          ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `f64`
   |
   = note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Float>` for `f64`
   = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `u16: diesel::Expression` is not satisfied
  --> src/models.rs:26:10
   |
26 | #[derive(Insertable, Debug, Queryable)]
   |          ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `u16`
   |
   = note: required because of the requirements on the impl of `diesel::Expression` for `&u16`
   = note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Unsigned<diesel::sql_types::Integer>>` for `&u16`
   = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `chrono::naive::datetime::NaiveDateTime: diesel::Expression` is not satisfied
  --> src/models.rs:26:10
   |
26 | #[derive(Insertable, Debug, Queryable)]
   |          ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `chrono::naive::datetime::NaiveDateTime`
   |
   = note: required because of the requirements on the impl of `diesel::Expression` for `&chrono::naive::datetime::NaiveDateTime`
   = note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Date>` for `&chrono::naive::datetime::NaiveDateTime`
   = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `f64: diesel::Expression` is not satisfied
  --> src/models.rs:26:10
   |
26 | #[derive(Insertable, Debug, Queryable)]
   |          ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `f64`
   |
   = note: required because of the requirements on the impl of `diesel::Expression` for `&f64`
   = note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Float>` for `&f64`
   = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `u16: diesel::Expression` is not satisfied
  --> src/models.rs:26:10
   |
26 | #[derive(Insertable, Debug, Queryable)]
   |          ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `u16`
   |
   = note: required because of the requirements on the impl of `diesel::Expression` for `&'insert u16`
   = note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Unsigned<diesel::sql_types::Integer>>` for `&'insert u16`
   = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `chrono::naive::datetime::NaiveDateTime: diesel::Expression` is not satisfied
  --> src/models.rs:26:10
   |
26 | #[derive(Insertable, Debug, Queryable)]
   |          ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `chrono::naive::datetime::NaiveDateTime`
   |
   = note: required because of the requirements on the impl of `diesel::Expression` for `&'insert chrono::naive::datetime::NaiveDateTime`
   = note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Date>` for `&'insert chrono::naive::datetime::NaiveDateTime`
   = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `f64: diesel::Expression` is not satisfied
  --> src/models.rs:26:10
   |
26 | #[derive(Insertable, Debug, Queryable)]
   |          ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `f64`
   |
   = note: required because of the requirements on the impl of `diesel::Expression` for `&'insert f64`
   = note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Float>` for `&'insert f64`
   = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]:不满足特性绑定'u16:diesel::Expression'
-->src/models.rs:26:10
|
26 |#[派生(可插入、调试、可查询)]
|^^^^^^^^未为'u16'实现trait'diesel::Expression'`
|
=注意:由于'u16'的'diesel::expression::AsExpression'的impl上的要求,因此需要`
=注意:此错误源于派生宏(在夜间构建中,使用-Z宏反向跟踪运行以获取更多信息)
错误[E0277]:未满足特性绑定'chrono::naive::datetime::NaiveDateTime:diesel::Expression'
-->src/models.rs:26:10
|
26 |#[派生(可插入、调试、可查询)]
|^^^^^^^^^^^未为'chrono::naive::datetime::NaiveDateTime'实现特性'diesel::Expression'`
|
=注意:由于对`chrono::naive::datetime::NaiveDateTime`的`diesel::expression::AsExpression`的impl有要求,因此必需`
=注意:此错误源于派生宏(在夜间构建中,使用-Z宏反向跟踪运行以获取更多信息)
错误[E0277]:未满足特性绑定'f64:diesel::Expression'
-->src/models.rs:26:10
|
26 |#[派生(可插入、调试、可查询)]
|^^^^^^^没有为`f64'实现特性`diesel::Expression``
|
=注意:由于对`f64`的`diesel::expression::AsExpression`的impl有要求,因此需要`
=注意:此错误源于派生宏(在夜间构建中,使用-Z宏反向跟踪运行以获取更多信息)
错误[E0277]:不满足特性绑定'u16:diesel::Expression'
-->src/models.rs:26:10
|
26 |#[派生(可插入、调试、可查询)]
|^^^^^^^^未为'u16'实现trait'diesel::Expression'`
|
=注意:由于“`&u16”的“diesel::Expression` impl中的要求,因此需要`
=注意:由于“&&u16”的“diesel::expression::AsExpression”impl上的要求,因此需要`
=注意:此错误源于派生宏(在夜间构建中,使用-Z宏反向跟踪运行以获取更多信息)
错误[E0277]:未满足特性绑定'chrono::naive::datetime::NaiveDateTime:diesel::Expression'
-->src/models.rs:26:10
|
26 |#[派生(可插入、调试、可查询)]
|^^^^^^^^^^^未为'chrono::naive::datetime::NaiveDateTime'实现特性'diesel::Expression'`
|
=注意:由于“&chrono::naive::datetime::NaiveDateTime”的“diesel::Expression”impl上的要求,因此必需`
=注意:由于“&&chrono::naive::datetime::NaiveDateTime”的“diesel::expression::AsExpression”impl上的要求,因此需要此选项`
=注意:此错误源于派生宏(在夜间构建中,使用-Z宏反向跟踪运行以获取更多信息)
错误[E0277]:未满足特性绑定'f64:diesel::Expression'
-->src/models.rs:26:10
|
26 |#[派生(可插入、调试、可查询)]
|^^^^^^^没有为`f64'实现特性`diesel::Expression``
|
=注意:由于“&f64”的“diesel::Expression”impl中的要求,因此需要`
=注意:由于对“&&f64”的“diesel::expression::AsExpression”impl的要求,因此需要此选项`
=注意:此错误源于派生宏(在夜间构建中,使用-Z宏反向跟踪运行以获取更多信息)
错误[E0277]:不满足特性绑定'u16:diesel::Expression'
-->src/models.rs:26:10
|
26 |#[派生(可插入、调试、可查询)]
|^^^^^^^^未为'u16'实现trait'diesel::Expression'`
|
=注:由于“&”insert u16的“diesel::Expression”impl中的要求,因此需要`
=注意:由于`&'insert u16对`diesel::expression::AsExpression`的impl有要求,因此需要`
=注意:此错误源于派生宏(在夜间构建中,使用-Z宏反向跟踪运行以获取更多信息)
错误[E0277]:未满足特性绑定'chrono::naive::datetime::NaiveDateTime:diesel::Expression'
-->src/models.rs:26:10
|
26 |#[派生(可插入、调试、可查询)]
|^^^^^^^^^^^未为'chrono::naive::datetime::NaiveDateTime'实现特性'diesel::Expression'`
|
=注意:由于`&'insert chrono::naive::datetime::NaiveDateTime的`diesel::Expression`的impl上的要求,因此必需`
=注意:由于`&'insert chrono::NAVIE::datetime::NAVIDATETIME::AsExpression`对`&'insert chrono::NAVIE::datetime::NAVIDATETIME`的impl有要求,因此必需`
=注意:此错误源于派生宏(在夜间构建中,使用-Z宏反向跟踪运行以获取更多信息)
错误[E0277]:未满足特性绑定'f64:diesel::Expression'
-->src/models.rs:26:10
|
26 |#[派生(可插入、调试、可查询)]
|^^^^^^^没有为`f64'实现特性`diesel::Expression``
|
=注意:由于“&”insert f64的“diesel::Expression”impl中的要求,因此需要`
=注意:由于“&”insert f64的“diesel::expression::AsExpression”impl中的要求,因此需要`
=注意:此错误源于派生宏(在夜间构建中,使用-Z宏反向跟踪运行以获取更多信息)
这是我的models.rs文件

use crate::schema::*;
use serde::{Deserialize, Serialize};
use chrono::NaiveDateTime;

#[derive(Debug, Serialize, Deserialize, Queryable)]
pub struct Site {
    pub site_id: i32,
    pub name: String,
    pub slug: String,
    pub rack_size: u16,
    pub date_created: chrono::NaiveDateTime,
    pub latitude: f64,
    pub longitude: f64 
}

//#[derive(Insertable, Debug, Queryable)]
//#[table_name = "site"]
//pub struct NewSite<'a> {
//    pub name: &'a str,
//    pub slug: &'a str,
//    pub rack_size: &'a  u16,
//    pub date_created: chrono::NaiveDateTime,
//    pub latitude: &'a f64,
//    pub longitude: &'a f64
//}
#[derive(Insertable, Debug, Queryable)]
#[table_name = "site"]
pub struct NewSite {
    pub name: String,
    pub slug: String,
    pub rack_size: u16,
    pub date_created: chrono::NaiveDateTime,
    pub latitude: f64,
    pub longitude: f64 
}
使用板条箱::模式::*;
使用serde::{反序列化,序列化};
使用chrono::NaiveDateTime;
#[派生(调试、序列化、反序列化、可查询)]
发布结构站点{
酒吧网站id:i32,
酒吧名称:String,
酒吧鼻涕虫:字符串,
酒吧架尺寸:u16,
pub date_created:chrono::NaiveDateTime,
酒吧纬度:f64,
酒吧经度:f64
}
//#[派生(可插入、调试、可查询)]
//#[选项卡
[package]
name = "micd"
version = "0.1.0"
authors = ["First Last <no@gmail.com>"]
edition = "2018"

[dependencies]
actix-web = "2.0.0"
actix-web-httpauth = { git = "https://github.com/actix/actix-web-httpauth" }
chrono = { version = "0.4.10", features = ["serde"] }
derive_more = "0.99.2"
diesel = { version = "1.4.2", features = ["extras", "mysql", "default"] }
dotenv = "0.15.0"
futures = "0.3.1"
r2d2 = "0.8.8"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
actix-service = "1.0.1"
alcoholic_jwt = "1.0.0"
reqwest = "0.9.22"
actix-rt = "1.0.0"