Reference Mods in other local packages

I have a set of Mod files in a workspace which I want to reference from another directory. But I cannot find the syntax I need to use. So the example is:

|_______ First
|            |_____ src
|                    |______
|_______ Second
            |_____ src

I want to reference a Struct in "Cool_things" from

In Primary cargo.toml I put something like:

members= ["First","Second", "Third"]

First= { path = "First" }

in the cargo.toml in the Second directory I have

First = { path = "../First" }

and I have been trying things in my like:

extern crate First;
use First::Cool_things::Cool_things;

but no variation of use, mod, seem to allow me to reference the struct or impl or functions in Mod Cool_things.

You need a in your First package with the following contents:

mod Cool_things;

That should cause use First::Cool_things::Cool_things to work in your other crate.

The important thing to remember is that mod is a module declaration, not an import. You should have exactly one mod statement for each module in your crate.

That worked. But broke other things. I'm wondering if I wouldn't be better off by putting all the Mod files into the top-level Primary/src directory and then accessing them from either First or Second?

So if is located in

|__ src

How do I tell the in Second and in First to look back up?

You would need to move the mod Cool_things statement into Primary's and then make First and Second have a dependency on Primary instead of the other way around.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.