shlogg · Early preview
Jeff Mitchell @sentinel1909

Rust Crates, Packages, And Modules Explained

Mastering crates, packages & modules in Rust takes time & practice. Understand crate types (binary & library), package structure, modules for organization & privacy control, paths, use keyword & namespace operator to write maintainable code.

Today, I will share my take on crates, packages, and modules in Rust. I've found Rust's organization system challenging to master, but with time and practice, it's finally starting to click.
Let's get the basics under our belt!

  
  
  Crates

A crate is the smallest unit of a Rust program. For instance, the Rust compiler considers this code sample a crate:

fn main() {
    println!("I am a crate.");
}

    
    

    
    




An important concept is the crate root. The crate root is where the compiler begins building a program. In the tiny example above, whatever we name the file, let's say...