Reputation: 533
I have a file structure looking somewhat like the following:
src/
--clients/
----queue_client/
------mod.rs
--data_evaluator/
----data_evaluator.rs
In data_evaluator, I want to use the queue_client
module, but when I do mod queue_client
in data_evaluator.rs
- I get the following error - File not found for module queue_client
. It only finds the module if I move it into the data_evaluator
folder.
My question is, how do I correctly use modules that are outside of the consumer code's directory? Apologies if there is an easy way to do this, I did try searching for quite a while and couldn't find a way.
Upvotes: 1
Views: 2072
Reputation: 339
You seem to be a bit confused.
In Rust, you build the module tree.
You use mod
to register a module as a submodule of your current module.
You use use
to use a module within your current module.
This article may clear some things up: http://www.sheshbabu.com/posts/rust-module-system/
Aside from that, to use a module that's higher in the tree than your current module, you use crate
to get to the root of your module tree.
So in your case, crate::clients::queue_client
.
Upvotes: 2