error[E0433]: failed to resolve: use of undeclared crate or module

Viewed 2332

I add the models when using rust diesel as ORM like this:

use rocket::serde::Serialize;
use rocket::serde::Deserialize;

#[derive(Insertable, Serialize, Queryable, Deserialize,Default)]
#[table_name = "dict"]
pub struct QueryEdict {
    pub id: i64,
    pub word: String,
    pub phonetic: String,
    pub definition: String,
    pub translation: String,
    pub pos: String,
    pub collins: String,
    pub oxford: String,
    pub tag: String,
    pub bnc: i32,
    pub frq: i32,
    pub exchange: String,
    pub detail: String,
    pub audio: String,
}

and generate scheme.rs like this:

table! {
    dict (id) {
        word -> Nullable<Varchar>,
        phonetic -> Nullable<Varchar>,
        definition -> Nullable<Varchar>,
        translation -> Nullable<Varchar>,
        pos -> Nullable<Varchar>,
        collins -> Nullable<Int4>,
        oxford -> Nullable<Int4>,
        tag -> Nullable<Varchar>,
        bnc -> Nullable<Int4>,
        frq -> Nullable<Int4>,
        exchange -> Nullable<Varchar>,
        detail -> Nullable<Varchar>,
        audio -> Nullable<Varchar>,
        id -> Int4,
    }
}

the main.rs look like this:

#[macro_use] extern crate rocket;

#[macro_use]
extern crate diesel;

mod schema;
mod models;

#[get("/<id>")]
fn index(id:&str) -> &'static str {
    return "ok";
}

#[launch]
fn rocket() -> _ {
    rocket::build().mount("/", routes![index])
}

and this is the dependencies:

[package]
name = "rust-learn"
version = "0.1.0"
edition = "2018"

[dependencies]
rocket = { version = "0.5.0-rc.1", features = ["json"] }
serde = { version = "1.0.64", features = ["derive"] }
serde_json = "1.0.64"
serde_derive = "1.0"
# database
diesel = { version = "1.4.7", features = ["postgres"] }
dotenv = "0.15.0"
jsonwebtoken = "7"
chrono = "0.4"

when I build the project, shows error like this:

error[E0433]: failed to resolve: use of undeclared crate or module `dict`
 --> src/models.rs:5:16
  |
5 | #[table_name = "dict"]
  |                ^^^^^^ use of undeclared crate or module `dict`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0433`.
error: could not compile `rust-learn`

am I missing something? what should I do to fix this problem?

0 Answers
Related