The rust compiler resolves modules differently depending on where they're defined.
When you use the mod
keyword to declare an external module from the crate entry point (typically main.rs
or lib.rs
) or from a module root (mod.rs
), the compiler will search for files adjacent to the declaring file. This is why it works properly when using mod image.rs
in your main.rs
file.
In other cases, the compiler will search for files in the folder with the same name as the declaring file. In your case, this means that your mod decoders;
line in image.rs
results in the compiler searching for the module in the image
subfolder - specifically checking image/decoders.rs
and image/decoders/mod.rs
.
To fix this, you can either move decoders.rs
to image/decoders.rs
if you want to keep decoders
as a submodule of image
, or alternatively place mod decoders;
in main.rs
and leave the file where it is.