Rust anatomy

From wikinotes


Project Components

A rust project comprises of

packages build/test/share a collection of crates
crates tree of modules that build a single library, or executable
modules organize scope/privacy of paths
paths files ?

Packages

A package is a collection of crates.

  • it may have multiple executable crates
  • it may only have one library crate

Crates

A crate can be either

  • a library (has src/lib.rs entrypoint)
  • an executable (has src/main.rs entrypoint)

Modules

Module names govern where they can be found within the filesystem.
Module locations are based on where they are defined

from the rust book:

backyard
├── Cargo.lock
├── Cargo.toml
└── src
    ├── garden
    │   └── vegetables.rs
    ├── garden.rs
    └── main.rs

The module foo's code could be

  • src/foo.rs
  • src/foo/mod.rs