Rust Diesel 未构建错误使用未声明的板条箱或模块
Rust Diesel not building with error use of undeclared crate or module
我正在尝试创建我的第一个支持数据库的 Rust 应用程序,我正在使用 Diesel 和 SQLite,每当我构建我的应用程序时,我都会收到以下错误消息:
failed to resolve: use of undeclared crate or module `categorys`
--> src/models.rs:14:12
|
14 | pub struct Category {
| ^^^^^^^^ use of undeclared crate or module `categorys`
error[E0433]: failed to resolve: use of undeclared crate or module `correspondents`
--> src/models.rs:21:12
|
21 | pub struct Correspondent {
| ^^^^^^^^^^^^^ use of undeclared crate or module `correspondents`
error[E0433]: failed to resolve: use of undeclared crate or module `doctypes`
--> src/models.rs:27:12
|
27 | pub struct Doctype {
| ^^^^^^^ use of undeclared crate or module `doctypes`
error[E0433]: failed to resolve: use of undeclared crate or module `documents`
--> src/models.rs:37:12
|
37 | pub struct Document {
| ^^^^^^^^ use of undeclared crate or module `documents`
error: aborting due to 4 previous errors
我的cargo.toml
:
[package]
name = "Rekorder"
version = "0.1.0"
authors = ["ossama"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
diesel = { version = "1.4.4", features = ["sqlite"] }
diesel_cli_ext = "0.3.6"
dotenv = "0.15.0"
chrono = "0.4"
[dependencies.gtk]
version = "0.9.0"
features = ["v3_16"]
[dependencies.gio]
version = ""
features = ["v2_44"]
我的models.rs
:
// Generated by diesel_ext
#![allow(unused)]
#![allow(clippy::all)]
use chrono::NaiveDate;
use diesel::Queryable;
use diesel::Identifiable;
use diesel::sql_types::Binary;
#[derive(Queryable, Debug, Identifiable)]
pub struct Category {
pub id: i32,
pub name: String,
pub color: Option<i32>,
}
#[derive(Queryable, Debug, Identifiable)]
pub struct Correspondent {
pub id: i32,
pub name: String,
}
#[derive(Queryable, Debug, Identifiable)]
pub struct Doctype {
pub id: i32,
pub name: String,
pub correspondent_name: Option<String>,
pub support_extra_date_number: Option<bool>,
pub icon: Option<Binary>,
}
#[derive(Queryable, Debug, Identifiable)]
#[primary_key(number, date_of_document, doc_type_id)]
pub struct Document {
pub number: i32,
pub date_of_document: NaiveDate,
pub doc_type_id: i32,
pub extra_number: Option<String>,
pub extra_date: Option<NaiveDate>,
pub correspondent_id: i32,
pub content: String,
pub notes: Option<String>,
pub category_id: Option<i32>,
pub document_file_name: Option<String>,
pub document_file_size: Option<i32>,
pub document_file: Option<Binary>,
}
我的schema.rs
:
table! {
category (id) {
id -> Integer,
name -> Text,
color -> Nullable<Integer>,
}
}
table! {
correspondent (id) {
id -> Integer,
name -> Text,
}
}
table! {
doctype (id) {
id -> Integer,
name -> Text,
correspondent_name -> Nullable<Text>,
support_extra_date_number -> Nullable<Bool>,
icon -> Nullable<Binary>,
}
}
table! {
document (number, date_of_document, doc_type_id) {
number -> Integer,
date_of_document -> Date,
doc_type_id -> Integer,
extra_number -> Nullable<Text>,
extra_date -> Nullable<Date>,
correspondent_id -> Integer,
content -> Text,
notes -> Nullable<Text>,
category_id -> Nullable<Integer>,
document_file_name -> Nullable<Text>,
document_file_size -> Nullable<Integer>,
document_file -> Nullable<Binary>,
}
}
joinable!(document -> category (category_id));
joinable!(document -> correspondent (correspondent_id));
joinable!(document -> doctype (doc_type_id));
allow_tables_to_appear_in_same_query!(
category,
correspondent,
doctype,
document,
);
最后是我的 main.rs
:
mod models;
fn main() {
println!("Hello, world!");
}
我尝试将 use schema::*
添加到我的 model.rs
但没有成功,因为找不到模型。
我也试过 this solution 没有成功。
我无法使用正确的范围,我是生锈的新手,我仍然习惯它的范例
Diesel 假定您的 table 名称是您的结构名称的复数蛇形形式。因为您的 table 名称不遵循此约定,您可以明确指定 table 名称:
#[derive(Queryable, Identifiable)]
#[table_name = "category"]
pub struct Category {
// ...
}
#[derive(Queryable, Identifiable)]
#[table_name = "correspondent"]
pub struct Correspondent {
// ...
}
// and do the same to the rest of your models...
我正在尝试创建我的第一个支持数据库的 Rust 应用程序,我正在使用 Diesel 和 SQLite,每当我构建我的应用程序时,我都会收到以下错误消息:
failed to resolve: use of undeclared crate or module `categorys`
--> src/models.rs:14:12
|
14 | pub struct Category {
| ^^^^^^^^ use of undeclared crate or module `categorys`
error[E0433]: failed to resolve: use of undeclared crate or module `correspondents`
--> src/models.rs:21:12
|
21 | pub struct Correspondent {
| ^^^^^^^^^^^^^ use of undeclared crate or module `correspondents`
error[E0433]: failed to resolve: use of undeclared crate or module `doctypes`
--> src/models.rs:27:12
|
27 | pub struct Doctype {
| ^^^^^^^ use of undeclared crate or module `doctypes`
error[E0433]: failed to resolve: use of undeclared crate or module `documents`
--> src/models.rs:37:12
|
37 | pub struct Document {
| ^^^^^^^^ use of undeclared crate or module `documents`
error: aborting due to 4 previous errors
我的cargo.toml
:
[package]
name = "Rekorder"
version = "0.1.0"
authors = ["ossama"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
diesel = { version = "1.4.4", features = ["sqlite"] }
diesel_cli_ext = "0.3.6"
dotenv = "0.15.0"
chrono = "0.4"
[dependencies.gtk]
version = "0.9.0"
features = ["v3_16"]
[dependencies.gio]
version = ""
features = ["v2_44"]
我的models.rs
:
// Generated by diesel_ext
#![allow(unused)]
#![allow(clippy::all)]
use chrono::NaiveDate;
use diesel::Queryable;
use diesel::Identifiable;
use diesel::sql_types::Binary;
#[derive(Queryable, Debug, Identifiable)]
pub struct Category {
pub id: i32,
pub name: String,
pub color: Option<i32>,
}
#[derive(Queryable, Debug, Identifiable)]
pub struct Correspondent {
pub id: i32,
pub name: String,
}
#[derive(Queryable, Debug, Identifiable)]
pub struct Doctype {
pub id: i32,
pub name: String,
pub correspondent_name: Option<String>,
pub support_extra_date_number: Option<bool>,
pub icon: Option<Binary>,
}
#[derive(Queryable, Debug, Identifiable)]
#[primary_key(number, date_of_document, doc_type_id)]
pub struct Document {
pub number: i32,
pub date_of_document: NaiveDate,
pub doc_type_id: i32,
pub extra_number: Option<String>,
pub extra_date: Option<NaiveDate>,
pub correspondent_id: i32,
pub content: String,
pub notes: Option<String>,
pub category_id: Option<i32>,
pub document_file_name: Option<String>,
pub document_file_size: Option<i32>,
pub document_file: Option<Binary>,
}
我的schema.rs
:
table! {
category (id) {
id -> Integer,
name -> Text,
color -> Nullable<Integer>,
}
}
table! {
correspondent (id) {
id -> Integer,
name -> Text,
}
}
table! {
doctype (id) {
id -> Integer,
name -> Text,
correspondent_name -> Nullable<Text>,
support_extra_date_number -> Nullable<Bool>,
icon -> Nullable<Binary>,
}
}
table! {
document (number, date_of_document, doc_type_id) {
number -> Integer,
date_of_document -> Date,
doc_type_id -> Integer,
extra_number -> Nullable<Text>,
extra_date -> Nullable<Date>,
correspondent_id -> Integer,
content -> Text,
notes -> Nullable<Text>,
category_id -> Nullable<Integer>,
document_file_name -> Nullable<Text>,
document_file_size -> Nullable<Integer>,
document_file -> Nullable<Binary>,
}
}
joinable!(document -> category (category_id));
joinable!(document -> correspondent (correspondent_id));
joinable!(document -> doctype (doc_type_id));
allow_tables_to_appear_in_same_query!(
category,
correspondent,
doctype,
document,
);
最后是我的 main.rs
:
mod models;
fn main() {
println!("Hello, world!");
}
我尝试将 use schema::*
添加到我的 model.rs
但没有成功,因为找不到模型。
我也试过 this solution 没有成功。
我无法使用正确的范围,我是生锈的新手,我仍然习惯它的范例
Diesel 假定您的 table 名称是您的结构名称的复数蛇形形式。因为您的 table 名称不遵循此约定,您可以明确指定 table 名称:
#[derive(Queryable, Identifiable)]
#[table_name = "category"]
pub struct Category {
// ...
}
#[derive(Queryable, Identifiable)]
#[table_name = "correspondent"]
pub struct Correspondent {
// ...
}
// and do the same to the rest of your models...