Trouble with 2018 mod system

#1

Hi I have a project I am having trouble moving the mod system from 2015 rust to 2018.

The 2015 code simplified has a structure like

src
 --- lib.rs
 --- elements
        ---- mod.rs
        ----  element1.rs
        ----  element2.rs
        ----  element3.rs
        .........

mod.rs contained lines like

pub mod element1; 
pub mod element2;
pub mod element3;
....

In lib.rs I had

pub mod elements;

The guide seems to indicate mod.rs is no longer needed
but the build returns

 file not found for module `elements`                                                                                                                                       
  --> src/lib.rs:25:9                                                                                                                                                                    
   |                                                                                                                                                                                     
25 | pub mod elements;         

How can I declare multiple files under a subdirectory as modules ?

Thanks

0 Likes

#2

If the module is not inline, you still need an intermediary file somewhere. It doesn’t have to to be src/elements/mod.rs, you can have it in src/elements.rs instead.

0 Likes

#3

The file is still needed. The file name doesn’t need to be mod.rs any more.

0 Likes

#4

Ah OK. My silly.

Thanks

0 Likes