Module 引用同级模块(如Diesel')的正确方式是什么;s生成的模式?
我正在构建一个web服务,它使用Diesel访问MySQL数据库。一切都已正确设置,Diesel正在生成包含反映我的数据库架构的内容的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的模块,该模块是板条箱模块的子模块。我的意图是将所有处理数据库内容的代码放在存储模块中。但是,
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自动生成的文件。我认为你不应该改变它。我也是个新手。对不起,如果这是误导或错误的。