> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Rust Crate Root

A crate root is the primary source file that the Rust compiler (`rustc`) uses as the entry point to compile a crate and construct its module tree. It serves as the root node of the crate's namespace hierarchy, implicitly defining a top-level module named `crate`.

## Standard File Conventions

By default, the Cargo build system looks for specific file paths to identify crate roots:

* **Binary Crate:** `src/main.rs`
* **Library Crate:** `src/lib.rs`

If a package contains both `src/main.rs` and `src/lib.rs`, it possesses two distinct crate roots, resulting in two separate crates (one binary, one library) compiled from the same package. Additional binary crate roots can be defined by placing files in the `src/bin/` directory.

## Module Tree Construction

The compiler only processes files that are explicitly included in the module tree. The crate root is responsible for declaring top-level child modules using the `mod` keyword. When the compiler encounters a `mod` declaration in the crate root, it searches the file system for the corresponding module implementation.

```rust theme={"dark"}
// src/lib.rs (Library Crate Root)

// Declares a child module. The compiler will look for `network.rs` or `network/mod.rs`.
pub mod network; 

// Declares another child module. The compiler will look for `storage.rs` or `storage/mod.rs`.
mod storage;

// Inline module defined directly within the crate root.
mod config {
    pub const TIMEOUT: u32 = 60;
}
```

## Path Resolution

Because the crate root establishes the base of the module hierarchy, absolute paths within the crate always begin with the `crate::` prefix, which explicitly references the crate root.

```rust theme={"dark"}
// src/main.rs (Binary Crate Root)

mod parser;
mod engine;

fn main() {
    // Absolute path starting from the crate root
    crate::engine::initialize();
    
    // Relative path (resolves successfully because main is in the crate root)
    parser::parse_input();
}
```

## Compilation Unit Boundary

The crate root defines the strict boundary of the compilation unit. Any `.rs` file in the project directory that is not declared via a `mod` statement originating from the crate root—either directly or transitively through child modules—is entirely ignored by the compiler. The compiler parses the crate root first, follows the `mod` declarations to other files, and aggregates all reachable modules into a single Abstract Syntax Tree (AST) to produce the final binary or library artifact.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Rust Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
