Hi guys I wanted to practice on how to create a library.
So to make sure I am clear, a library is nothing but a crate, right? And it is like just calling a function in the bin file from the lib file, am I correct?
And if this is true, then do I create the library inside the main project, right?
Any project that has a lib.rs file has a library, and lib.rs is the root of the library. If you also have binaries in the same project, then you can access the library with use your_package_name::stuff;
In this example, the library consists of the following files:
src/lib.rs
src/module1.rs
src/module2.rs
and the binary consists of:
src/main.rs
src/main_helper.rs
To determined whether a file is part of the binary or library, you should see whether the mod filename statement is in the lib.rs or main.rs file. You should not mention a file in both main.rs and lib.rs with a mod statement. If you want to access it from both, put the mod statement in lib.rs and use a use statement in main.rs.