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
Rust 在柴油塔中使用新类型_Rust_Newtype_Rust Diesel - Fatal编程技术网

Rust 在柴油塔中使用新类型

Rust 在柴油塔中使用新类型,rust,newtype,rust-diesel,Rust,Newtype,Rust Diesel,我正在使用新类型,如struct GuildId(i64)用于my diesel模型结构中的列。目前,我正在实施以下特征: #[derive(Debug, Display, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize)] pub struct $name(pub i64); impl AsExpression<BigInt> for $name { /* delegate to <i6

我正在使用新类型,如
struct GuildId(i64)用于my diesel模型结构中的列。目前,我正在实施以下特征:

#[derive(Debug, Display, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize)]
pub struct $name(pub i64);

impl AsExpression<BigInt> for $name { /* delegate to <i64 as AsExpression<BigInt> */ */ }

impl<ST, DB: Backend> Queryable<ST, DB> for $name
where i64: FromSql<ST, DB> { /* also delegate to i64 */
频道
仍不执行
归属于DSL
。当我尝试将其转换为trait时,它无法编译,并显示以下消息:

error[E0277]: the trait bound `diesel::query_builder::select_statement::SelectStatement<webcord_schema::schema::channels::table>: diesel::query_dsl::filter_dsl::FilterDsl<diesel::expression::operators::Eq<webcord_schema::schema::channels::columns::guild_id, &webcord_schema::models::GuildId>>` is not satisfied
  --> src/index/guild.rs:23:32
   |
23 |                 let channels = <models::Channel as BelongingToDsl<&models::Guild>>::belonging_to(&guild)
   |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `diesel::query_dsl::filter_dsl::FilterDsl<diesel::expression::operators::Eq<webcord_schema::schema::channels::columns::guild_id, &webcord_schema::models::GuildId>>` is not implemented for `diesel::query_builder::select_statement::SelectStatement<webcord_schema::schema::channels::table>`
   |
   = help: the following implementations were found:
             <diesel::query_builder::select_statement::SelectStatement<F, S, D, W, O, L, Of, G, LC> as diesel::query_dsl::filter_dsl::FilterDsl<Predicate>>
   = note: required because of the requirements on the impl of `diesel::query_dsl::filter_dsl::FilterDsl<diesel::expression::operators::Eq<webcord_schema::schema::channels::columns::guild_id, &webcord_schema::models::GuildId>>` for `webcord_schema::schema::channels::table`

error[E0277]: the trait bound `webcord_schema::models::GuildId: diesel::expression::Expression` is not satisfied
  --> src/index/guild.rs:23:32
   |
23 |                 let channels = <models::Channel as BelongingToDsl<&models::Guild>>::belonging_to(&guild)
   |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `diesel::expression::Expression` is not implemented for `webcord_schema::models::GuildId`
   |
   = note: required because of the requirements on the impl of `diesel::expression::Expression` for `&webcord_schema::models::GuildId`
   = note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::BigInt>` for `&webcord_schema::models::GuildId`
   = note: required because of the requirements on the impl of `diesel::query_dsl::belonging_to_dsl::BelongingToDsl<&webcord_schema::models::Guild>` for `webcord_schema::models::Channel`
error[E0277]:特性绑定的'diesel::query\u builder::select\u语句::SelectStatement:diesel::query\u dsl::filter\u dsl::FilterDsl'不满足
-->src/index/guild.rs:23:32
|
23 | let channels=::属于(&guild)
|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^未为`柴油机::查询生成器::选择语句::选择语句'实现特性`柴油机::查询dsl::过滤dsl::过滤dsl'`
|
=帮助:找到了以下实现:
=注意:之所以需要,是因为对于“webcord\u schema::schema::channels::table”的“diesel::query\u dsl::filter\u dsl::FilterDsl”impl中的要求`
错误[E0277]:未满足特性绑定的'webcord_schema::models::Guidid:diesel::expression::expression'
-->src/index/guild.rs:23:32
|
23 | let channels=::属于(&guild)
|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^未为`
|
=注意:由于“`&webcord_schema::models::Guidid”的“diesel::expression::expression`impl”上的要求,因此需要`
=注意:由于“&webcord_schema::models::Guidid”的“diesel::expression::AsExpression”impl中的要求,因此需要此选项`
=注意:由于“webcord\u schema::models::Channel”的“diesel::query\u dsl::besting\u to\u dsl::besting todsl”impl中的要求,因此需要`

我缺少哪些特征?

该错误与
归属于DSL
无关,而是与自定义新类型包装器的不完整实现有关

由于错误消息表明您缺少新类型包装器的trait impl:

error[E0277]: the trait bound `webcord_schema::models::GuildId: diesel::expression::Expression` is not satisfied
  --> src/index/guild.rs:23:32
   |
23 |                 let channels = <models::Channel as BelongingToDsl<&models::Guild>>::belonging_to(&guild)
   |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `diesel::expression::Expression` is not implemented for `webcord_schema::models::GuildId`
   |
   = note: required because of the requirements on the impl of `diesel::expression::Expression` for `&webcord_schema::models::GuildId`
   = note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::BigInt>` for `&webcord_schema::models::GuildId`
   = note: required because of the requirements on the impl of `diesel::query_dsl::belonging_to_dsl::BelongingToDsl<&webcord_schema::models::Guild>` for `webcord_schema::models::Channel`

belovingtodsl
trait需要一个类型参数。我对柴油机没有经验,但可能是柴油机属于柴油机?是的,我忘了放那个。但是它仍然有下面的要求,我更新了错误。很抱歉很长时间没有接受答案。我停止了那个项目的工作,所以我还没有验证你的答案。但是感谢您的努力。
#[sql_type=“diesel::sql_types::BigInt”]是和@M.Leonhard上的diesel文档页面缺少的东西。这并不奇怪,因为这两个特征都与此属性无关。是这样的。ToSql和FromSql之间的关系非常密切,他们的文档说要添加
#[派生(AsExpression)]
。但是他们没有说“并且还添加了这个sql类型属性”或“检查AsExpression文档以了解特殊需求”。AsExpression派生错误消息没有说“缺少sql类型属性”。因此,用户很容易错过关键信息,并浪费大量时间搜索解决方案。
error[E0277]: the trait bound `webcord_schema::models::GuildId: diesel::expression::Expression` is not satisfied
  --> src/index/guild.rs:23:32
   |
23 |                 let channels = <models::Channel as BelongingToDsl<&models::Guild>>::belonging_to(&guild)
   |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `diesel::expression::Expression` is not implemented for `webcord_schema::models::GuildId`
   |
   = note: required because of the requirements on the impl of `diesel::expression::Expression` for `&webcord_schema::models::GuildId`
   = note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::BigInt>` for `&webcord_schema::models::GuildId`
   = note: required because of the requirements on the impl of `diesel::query_dsl::belonging_to_dsl::BelongingToDsl<&webcord_schema::models::Guild>` for `webcord_schema::models::Channel`