The Missing Bit

TIL - Rust crate lib and binaries are separate compile unit

Given a rust crate with three files:

lib.rs
main.rs
common.rs

When lib.rs and main.rs are compiled, they are each compiled in their own independant compile unit. This means that we have to put mod common inside each file.

But the better approach is to put mod common inside lib.rs and do use my_crate_name::common inside main.rs or other binaries within the crate.