Package Layout - The Cargo Book (original) (raw)

Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The Cargo Book

Package Layout

Cargo uses conventions for file placement to make it easy to dive into a new Cargo [package](../appendix/glossary.html#package ""package" (glossary entry)"):

.
├── Cargo.lock
├── Cargo.toml
├── src/
│   ├── lib.rs
│   ├── main.rs
│   └── bin/
│       ├── named-executable.rs
│       ├── another-executable.rs
│       └── multi-file-executable/
│           ├── main.rs
│           └── some_module.rs
├── benches/
│   ├── large-input.rs
│   └── multi-file-bench/
│       ├── main.rs
│       └── bench_module.rs
├── examples/
│   ├── simple.rs
│   └── multi-file-example/
│       ├── main.rs
│       └── ex_module.rs
└── tests/
    ├── some-integration-tests.rs
    └── multi-file-test/
        ├── main.rs
        └── test_module.rs

If a binary, example, bench, or integration test consists of multiple source files, place a main.rs file along with the extra [_modules_](../appendix/glossary.html#module ""module" (glossary entry)")within a subdirectory of the src/bin, examples, benches, or testsdirectory. The name of the executable will be the directory name.

Note: By convention, binaries, examples, benches and integration tests follow kebab-case naming style, unless there are compatibility reasons to do otherwise (e.g. compatibility with a pre-existing binary name). Modules within those targets are snake_case following the Rust standard.

You can learn more about Rust’s module system in the book.

See Configuring a target for more details on manually configuring targets. See Target auto-discovery for more information on controlling how Cargo automatically infers target names.