August Feng

Rust code organization

About

I've read the Managing Growing Projects with Packages, Crates and Modules from the rust book a dozen times now but I always forget the details of it.

Hopefully building a diagram will connect me to this group of rust-enabled neurons faster.

Diagram

graph TD subgraph package subgraph crate subgraph file/module ["file/module"] crate_root_file("`_src/main.rs_ or _src/lib.rs_`") end subgraph file'/module ["file/module"] _("...") end subgraph file''/module ["file/module"] submodule submodule' submodule'' end file/module --> file'/module file/module --> submodule file/module --> submodule' file/module --> submodule'' end subgraph crate' _'("...") end subgraph crate'' _''("...") end end

Targets

The chapter does not cover targets, but I think it was used interchangeably with the crate concept in section 7.1 when it's mentioned that binary and library crates share the same name.

I ran a small experiment with with both src/main.rs and src/lib.rs to see if the crates could reference each other using the same crate name. Only the binary crate could reference the library crate by the package name.

It would make sense that the documentation meant the name field in targets, considering how closely they are related.

Cargo packages consist of targets which correspond to source files which can be compiled into a crate.