Using File hierarchy

Hi everybody,
I am trying to split in different files a file which contains all the structs of my database
So I create a directory models which contains the different files for each structs
I have read the documentation but It seems to be more complex
The compiler says:
unresolved import models::MyappPathology**
use models::MyappPathology;
no MyappPathology in models**

This file exists
Please help to understand how it works

Best Regards


  1. Make sure there's only one mod models in the whole program. Every module must be created exactly once (mod behaves exactly like fn and struct).

  2. Use crate::models to refer to src/ which has been created by putting mod models; in src/

  3. Ensure there's pub struct MyappPathology in src/ Specifically the pub part.

I have checked there is one mod models in the whole program

I solve the problem by creating a file in models directory which contains
pub mod MyappPathology;


In the documentation, it is suggested not to specify a file with the name of the module

But without the file in the subdirectory models
It is not working

Oh, I thought MyappPathology was meant to be a struct. Rust's naming scheme suggests using all-lowercase names for modules.

Ok I change the name and use lowercase

if you want crate::modules::myapp_pathology::SomeStructName to work, then all the modules in the path must exist, so both mod modules in src/, and then mod myapp_pathology in src/ or src/modules/, and then it'll make a module from src/modules/

You must declare every module, but you don't have to have a file on disk for every module. Instead of mod modules; loaded from file, you can have mod modules { /* content of the file goes here */ }

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.