Calling a second module from a first module (not from main)

    1. I have create a new project with cargo.
    1. I the src/ folder, I have a main.rs file.
    1. I have added an m1.rs file and I can refer it in main.rs as m1 (imported with : "mod m1").

My question is : how can I do the same for m1: i.e. create an m2.rs file which I can import as m1 into m2 and refer to as m1?

Simply trying to import m2 into m1 as if m1 was main.rs does not seem to work.

Ops !
Just found out.
"mod m2" goes into main.rs as well as "mod m1" (and not into m2.rs, oddly).

mod works exactly like struct, enum, and fn. It creates a new named thing in the file where you write it.

1 Like

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.