Crate function available outside using lib?

Hi,

I create a project that is a server.
It has a main.rs that must be launched.

I create integration test.
In my ./tests/integration_test.rs I would like to use just one function that is in my project.

So, I created a lib.rs and just add in :

pub mod some_module_in_my_project;
use some_module_in_my_project::get_datas;

The only problem is that I have a warning when I run my project because there is only this code in my lib.rs. How can we share functionalities in rust the good way please ?

warning: unused import: `some_module_in_my_project::get_datas`
 --> src/lib.rs:4:5
  |
4 | use some_module_in_my_project::get_datas;
  |     ^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

You neither use, nor re-export get_datas in lib.rs, hence the warning.
Just remove that line and you should be fine.

Alternatively you can make the inner module private and re-export get_datas in lib.rs like so:

mod some_module_in_my_project;
pub use some_module_in_my_project::get_datas;

And then use it as

use my_library::get_datas;

...

in an external program e.g. your integration test.

Note that for any of this to work, get_data itself must have been declared pub.

1 Like

I do not have the warning anymore in lib.rs
But now I have warning for others functions that are pub in

some_module_in_my_project

and warning for const not used that are not pub... !?

I don't want to share this other functionalities...

Oh ! I just pub for the two and it works !!! Thank you very much !