I'm trying to learn Rust by using it with actix-web
and diesel
.
When I try to import/use the schema by using the crate name it only works in the example.rs
file but not in the post.rs
file. Both files are nested in their own folders and the command I'm using is the following:
use web_project_core::schema::posts;
When I use this other command instead, it works in post.rs
but not in example.rs
:
use super::super::schema::posts;
What am I missing?
// Cargo.toml
[lib]
name = "web_project_core"
path = "src/lib.rs"
[[bin]]
name = "main"
path = "src/main.rs"
// main.rs
use actix_web::{App, HttpServer};
mod handlers;
// lib.rs
#[macro_use]
extern crate diesel;
extern crate dotenv;
use diesel::prelude::*;
use diesel::pg::PgConnection;
use dotenv::dotenv;
use std::env;
pub mod schema;
pub mod modelz;
// post.rs
use serde::{Serialize, Deserialize};
use nanoid::generate;
use super::super::schema::posts; // <-- it works
// use web_project_core::schema::posts; // <-- it doesn't work
// example.rs
use actix_web::{get, web, post, HttpResponse, Responder};
use diesel::prelude::*;
use web_project_core::establish_connection;
use web_project_core::schema::posts; // <-- it works
// use super::super::schema::posts; // <-- it doesn't work
use web_project_core::modelz::post::*;
The project structure:
Thanks