Skip to content

Latest commit

 

History

History
35 lines (21 loc) · 1.01 KB

d1.code_organization.md

File metadata and controls

35 lines (21 loc) · 1.01 KB

title: Code Organization

When a single code block is getting larger, it should be decomposed into smaller pieces and should be organized in a proper manner. Rust supports different levels of code organization.

Can be mapped to a,

  • Inline module
  • File
  • Directory hierarchy

Can be mapped to a,

  • lib.rs file on the same executable crate

  • Dependency crate specified on Cargo.toml

    Can be specified from,

    • Path
    • Git repository
    • crates.io

Helps to manage multiple crates as a single project.

Let’s discuss one by one.

💡 To make examples more simpler, we use a simple function which prints “Hello, world!”. But regarding writing testable codes, always try to return the String from the function and print it when calling it, instead of printing the String inside the function.