1

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.

WhoopsBing
  • 493
  • 1
  • 6
  • 12
  • `crate::clients::queue_client` – PitaJ Apr 26 '21 at 21:03
  • 1
    You seem to be confusing `mod` and `use`. Use defines a new module and should be located in new module's direct parent. So your structure should be `crate root { mod clients { mod queue_client }; mod data_evaluator { use crate::clients::queue_client } }`. Also note that `mod.rs` is a bit outdated: since 2018 edition `src/main.rs; module/submodule.rs; module.rs` is the preferred file structure. Also note that you can only `use` items that are marked as `pub`. – Ivan C Apr 26 '21 at 21:18
  • Does this answer your question? [Rust mod files in the same folder vs use](https://stackoverflow.com/questions/67035679/rust-mod-files-in-the-same-folder-vs-use) – Jmb Apr 27 '21 at 07:17

1 Answers1

1

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.

Rein F
  • 320
  • 3
  • 9