0

I want to separate the application logic to keep my main.rs file clean. I am using diesel for a simple project and I have the following files inside /src folder

  • main.rs
  • lib.rs
  • models.rs
  • schema.rs

I tried declaring the modules inside main.rs file and using them in the lib.rs file but that produces the following error:

unresolved import models; no models external crate [E0432]

main.rs looks like this:

pub mod lib;
pub mod schema;
pub mod models;

lib.rs produces error with this:

pub use models;
pub use schema::sent_sms;

I do not understand why things need to be so awfully complicated in this language, or maybe I am too stupid to understand it. Please help me understand.

Octav
  • 5
  • 2
  • 1
    [Minimal example to reproduce the error](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=fde9a8b3939a937d601b2879d89817ba). That's really not a helpful error message :/ (it get's better if you use something from that module) – Lukas Kalbertodt Feb 07 '19 at 15:59

1 Answers1

1

The main part of this answer was moved to the duplicate question!

So your problem is that use models; looks for models relative to the current module (lib). But models is not a sub module of lib, but of main. So the correct way to refer to these top level modules is like that:

use crate::{
    models,
    schema::sent_sms,
}; 

Additional notes:

  • If you have a executable project and just need a module to have some utility functions in, you usually wouldn't call it lib as that name is the default name for library crates' roots.
  • This use statement behavior changed with Rust 2018 (≥ 1.31))
  • Read this guide for more information about use statements and how they changed in Rust 2018
Lukas Kalbertodt
  • 79,749
  • 26
  • 255
  • 305