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
Module 引用同级模块(如Diesel')的正确方式是什么;s生成的模式?_Module_Rust_Schema_Rust Diesel - Fatal编程技术网

Module 引用同级模块(如Diesel')的正确方式是什么;s生成的模式?

Module 引用同级模块(如Diesel')的正确方式是什么;s生成的模式?,module,rust,schema,rust-diesel,Module,Rust,Schema,Rust Diesel,我正在构建一个web服务,它使用Diesel访问MySQL数据库。一切都已正确设置,Diesel正在生成包含反映我的数据库架构的内容的schema.rs文件: table! { user (id) { // ... } } 我创建了一个store.rs文件,该文件位于main.rs旁边。如果我对模块的理解正确,我放入store.rs文件中的任何代码都将属于名为store的模块,该模块是板条箱模块的子模块。我的意图是将所有处理数据库内容的代码放在存储模块中。但是,

我正在构建一个web服务,它使用Diesel访问MySQL数据库。一切都已正确设置,Diesel正在生成包含反映我的数据库架构的内容的
schema.rs
文件:

table! {
    user (id) {
        // ...
    }
}
我创建了一个
store.rs
文件,该文件位于
main.rs
旁边。如果我对模块的理解正确,我放入
store.rs
文件中的任何代码都将属于名为
store
的模块,该模块是
板条箱
模块的子模块。我的意图是将所有处理数据库内容的代码放在
存储
模块中。但是,我似乎无法
使用
模式中
模块中的
内容来开始使用Diesel API进行查询

我试过:

  • 使用模式
  • 使用板条箱::模式
  • 使用super::schema
  • 使用super::schema::user
什么都不管用。编译器总是说它无法解析路径的一部分或另一部分


在Rust中引用同级模块的正确方法是什么?

我希望这会有所帮助

店内销售

use crate::schema::*;

// … any other diesel related code you want to put here
大体上

pub mod schema;
mod store;

在main.rs中,确保为#[macro_use]设置diesel并导入模式mod

#[macro_use]
extern crate diesel;
mod schema;
在store.rs中,您应该能够使用您认为合适的模式

use crate::schema::user;

main.rs
schema.rs
中是否有
pub mod schema
语句。rs
是Diesel自动生成的文件。我认为你不应该改变它。我也是个新手。对不起,如果这是误导或错误的。