0

I don't really know Rust yet, but I have a project that I want to contain a bunch of small Rust programs with a file of a few functions that can be used in all the programs.

I can't seem to get it to be able to see the utils.rs file with this specific structure.

directory tree:

rust_stuff
|
|_ Cargo.lock
|_ Cargo.toml
|_ src/
|  |_ bin/
|     |_ project1.rs
|     |_ project2.rs
|     |_ ...more projects...
|
|_ utils.rs  // file of functions to use in all programs

In project1.rs I have tried use crate::utils; and also use utils::func1; and neither seems to be able to find it. Also, the functions in utils.rs are public. And I've tried a mod.rs file containing pub mod utils; and that didn't seem to do anything.

Is it possible to have this structure? If so, what am I doing wrong?

breakthatbass
  • 356
  • 1
  • 3
  • 11
  • As the linked answer says: ***Don't**. Put all of your source code into the src directory*. You probably want a [workspace](https://doc.rust-lang.org/book/ch14-03-cargo-workspaces.html). See also [Rust package with both a library and a binary?](https://stackoverflow.com/q/26946646/155423) – Shepmaster Nov 30 '21 at 16:44
  • You can use the library crate in your package for the common code, i.e. add the common code to `src/lib.rs` and import it using `use package_name::…`. – Sven Marnach Dec 01 '21 at 13:46

0 Answers0