[{"data":1,"prerenderedAt":1350},["ShallowReactive",2],{"page-\u002Frust\u002F20-modules-and-crates":3},{"id":4,"title":5,"body":6,"description":16,"extension":1344,"meta":1345,"navigation":787,"path":1346,"seo":1347,"stem":1348,"__hash__":1349},"content\u002Frust\u002F20-modules-and-crates.md","20 — Modules, Crates, Packages & Paths",{"type":7,"value":8,"toc":1313},"minimark",[9,13,17,22,67,71,150,164,168,176,185,192,330,335,382,385,392,436,439,451,471,513,517,620,623,677,680,684,690,694,723,727,733,742,750,754,806,813,817,838,863,873,877,898,912,916,925,953,960,964,968,974,978,1011,1015,1143,1150,1156,1160,1250,1254,1283,1287,1306,1309],[10,11,5],"h1",{"id":12},"_20-modules-crates-packages-paths",[14,15,16],"p",{},"Rust's module system controls visibility, organization, and namespacing.",[18,19,21],"h2",{"id":20},"definitions","Definitions",[23,24,25,38,52,58],"ul",{},[26,27,28,32,33,37],"li",{},[29,30,31],"strong",{},"Package",": a Cargo project (a ",[34,35,36],"code",{},"Cargo.toml"," + one or more crates).",[26,39,40,43,44,47,48,51],{},[29,41,42],{},"Crate",": a compilation unit (binary or library). Root file (",[34,45,46],{},"main.rs","\u002F",[34,49,50],{},"lib.rs",").",[26,53,54,57],{},[29,55,56],{},"Module",": a named scope inside a crate. Controls visibility.",[26,59,60,63,64,51],{},[29,61,62],{},"Path",": how you reference an item (",[34,65,66],{},"crate::foo::bar",[18,68,70],{"id":69},"module-declaration","Module Declaration",[72,73,75],"code-wrapper",{"language":74},"rust",[76,77,81],"pre",{"className":78,"code":79,"language":74,"meta":80,"style":80},"language-rust shiki shiki-themes github-light github-dark","\u002F\u002F src\u002Flib.rs\nmod network;\nmod ui {\n    pub mod window;\n    pub mod button;\n}\n","",[34,82,83,92,107,118,132,144],{"__ignoreMap":80},[84,85,88],"span",{"class":86,"line":87},"line",1,[84,89,91],{"class":90},"sdCPZ","\u002F\u002F src\u002Flib.rs\n",[84,93,95,99,103],{"class":86,"line":94},2,[84,96,98],{"class":97},"svdQ7","mod",[84,100,102],{"class":101},"sIsaT"," network",[84,104,106],{"class":105},"ssxIu",";\n",[84,108,110,112,115],{"class":86,"line":109},3,[84,111,98],{"class":97},[84,113,114],{"class":101}," ui",[84,116,117],{"class":105}," {\n",[84,119,121,124,127,130],{"class":86,"line":120},4,[84,122,123],{"class":97},"    pub",[84,125,126],{"class":97}," mod",[84,128,129],{"class":101}," window",[84,131,106],{"class":105},[84,133,135,137,139,142],{"class":86,"line":134},5,[84,136,123],{"class":97},[84,138,126],{"class":97},[84,140,141],{"class":101}," button",[84,143,106],{"class":105},[84,145,147],{"class":86,"line":146},6,[84,148,149],{"class":105},"}\n",[14,151,152,155,156,159,160,163],{},[34,153,154],{},"mod network;"," looks for ",[34,157,158],{},"network.rs"," or ",[34,161,162],{},"network\u002Fmod.rs"," (legacy) and includes it as a submodule.",[18,165,167],{"id":166},"file-layout-conventions-2018","File Layout Conventions (2018+)",[76,169,174],{"className":170,"code":172,"language":173},[171],"language-text","src\u002F\n├── lib.rs            \u002F\u002F crate root: `pub mod ...`\n├── main.rs\n├── network.rs        \u002F\u002F corresponds to `mod network;`\n└── network\u002F\n    └── server.rs     \u002F\u002F corresponds to `mod server;` *inside* network.rs\n","text",[34,175,172],{"__ignoreMap":80},[14,177,178,179,181,182,184],{},"The 2018 edition prefers ",[34,180,158],{}," over ",[34,183,162],{},". Don't mix the two for the same module.",[18,186,188,191],{"id":187},"use-importing",[34,189,190],{},"use"," — Importing",[72,193,194],{"language":74},[76,195,197],{"className":78,"code":196,"language":74,"meta":80,"style":80},"use std::collections::HashMap;\nuse std::io::{self, Read, Write};   \u002F\u002F bring multiple items\nuse std::io::Read as IoRead;        \u002F\u002F alias\nuse crate::network::server;          \u002F\u002F absolute path from crate root\nuse super::sibling;                  \u002F\u002F one module up\nuse self::inner;                     \u002F\u002F current module\n",[34,198,199,219,256,282,300,315],{"__ignoreMap":80},[84,200,201,203,206,209,212,214,217],{"class":86,"line":87},[84,202,190],{"class":97},[84,204,205],{"class":101}," std",[84,207,208],{"class":97},"::",[84,210,211],{"class":101},"collections",[84,213,208],{"class":97},[84,215,216],{"class":101},"HashMap",[84,218,106],{"class":105},[84,220,221,223,225,227,230,232,235,239,242,245,247,250,253],{"class":86,"line":94},[84,222,190],{"class":97},[84,224,205],{"class":101},[84,226,208],{"class":97},[84,228,229],{"class":101},"io",[84,231,208],{"class":97},[84,233,234],{"class":105},"{",[84,236,238],{"class":237},"snvgF","self",[84,240,241],{"class":105},", ",[84,243,244],{"class":101},"Read",[84,246,241],{"class":105},[84,248,249],{"class":101},"Write",[84,251,252],{"class":105},"};   ",[84,254,255],{"class":90},"\u002F\u002F bring multiple items\n",[84,257,258,260,262,264,266,268,270,273,276,279],{"class":86,"line":109},[84,259,190],{"class":97},[84,261,205],{"class":101},[84,263,208],{"class":97},[84,265,229],{"class":101},[84,267,208],{"class":97},[84,269,244],{"class":101},[84,271,272],{"class":97}," as",[84,274,275],{"class":101}," IoRead",[84,277,278],{"class":105},";        ",[84,280,281],{"class":90},"\u002F\u002F alias\n",[84,283,284,286,289,292,294,297],{"class":86,"line":120},[84,285,190],{"class":97},[84,287,288],{"class":97}," crate::",[84,290,291],{"class":101},"network",[84,293,208],{"class":97},[84,295,296],{"class":105},"server;          ",[84,298,299],{"class":90},"\u002F\u002F absolute path from crate root\n",[84,301,302,304,307,309,312],{"class":86,"line":134},[84,303,190],{"class":97},[84,305,306],{"class":237}," super",[84,308,208],{"class":97},[84,310,311],{"class":105},"sibling;                  ",[84,313,314],{"class":90},"\u002F\u002F one module up\n",[84,316,317,319,322,324,327],{"class":86,"line":146},[84,318,190],{"class":97},[84,320,321],{"class":237}," self",[84,323,208],{"class":97},[84,325,326],{"class":105},"inner;                     ",[84,328,329],{"class":90},"\u002F\u002F current module\n",[331,332,334],"h3",{"id":333},"glob-imports","Glob Imports",[72,336,337],{"language":74},[76,338,340],{"className":78,"code":339,"language":74,"meta":80,"style":80},"use std::io::prelude::*;            \u002F\u002F rare; usually too broad\nuse crate::network::*;               \u002F\u002F bring all public items\n",[34,341,342,366],{"__ignoreMap":80},[84,343,344,346,348,350,352,354,357,360,363],{"class":86,"line":87},[84,345,190],{"class":97},[84,347,205],{"class":101},[84,349,208],{"class":97},[84,351,229],{"class":101},[84,353,208],{"class":97},[84,355,356],{"class":101},"prelude",[84,358,359],{"class":97},"::*",[84,361,362],{"class":105},";            ",[84,364,365],{"class":90},"\u002F\u002F rare; usually too broad\n",[84,367,368,370,372,374,376,379],{"class":86,"line":94},[84,369,190],{"class":97},[84,371,288],{"class":97},[84,373,291],{"class":101},[84,375,359],{"class":97},[84,377,378],{"class":105},";               ",[84,380,381],{"class":90},"\u002F\u002F bring all public items\n",[14,383,384],{},"Avoid glob imports except for preludes.",[18,386,388,391],{"id":387},"pub-use-re-exports",[34,389,390],{},"pub use"," — Re-exports",[72,393,394],{"language":74},[76,395,397],{"className":78,"code":396,"language":74,"meta":80,"style":80},"\u002F\u002F lib.rs\npub mod api;\npub use api::Client;   \u002F\u002F re-export so users can `use my_crate::Client`\n",[34,398,399,404,416],{"__ignoreMap":80},[84,400,401],{"class":86,"line":87},[84,402,403],{"class":90},"\u002F\u002F lib.rs\n",[84,405,406,409,411,414],{"class":86,"line":94},[84,407,408],{"class":97},"pub",[84,410,126],{"class":97},[84,412,413],{"class":101}," api",[84,415,106],{"class":105},[84,417,418,420,423,425,427,430,433],{"class":86,"line":109},[84,419,408],{"class":97},[84,421,422],{"class":97}," use",[84,424,413],{"class":101},[84,426,208],{"class":97},[84,428,429],{"class":101},"Client",[84,431,432],{"class":105},";   ",[84,434,435],{"class":90},"\u002F\u002F re-export so users can `use my_crate::Client`\n",[14,437,438],{},"Re-export is the standard way to flatten the public API and hide internal structure.",[18,440,442,443,241,446,241,448],{"id":441},"paths-and-crate-self-super","Paths and ",[34,444,445],{},"crate",[34,447,238],{},[34,449,450],{},"super",[23,452,453,459,465],{},[26,454,455,458],{},[34,456,457],{},"crate::"," — absolute from crate root.",[26,460,461,464],{},[34,462,463],{},"self::"," — current module.",[26,466,467,470],{},[34,468,469],{},"super::"," — parent module.",[72,472,473],{"language":74},[76,474,476],{"className":78,"code":475,"language":74,"meta":80,"style":80},"\u002F\u002F in src\u002Fnetwork\u002Fserver.rs\nuse super::connection;     \u002F\u002F src\u002Fnetwork\u002Fconnection.rs\nuse crate::network::connection;   \u002F\u002F same, explicit\n",[34,477,478,483,497],{"__ignoreMap":80},[84,479,480],{"class":86,"line":87},[84,481,482],{"class":90},"\u002F\u002F in src\u002Fnetwork\u002Fserver.rs\n",[84,484,485,487,489,491,494],{"class":86,"line":94},[84,486,190],{"class":97},[84,488,306],{"class":237},[84,490,208],{"class":97},[84,492,493],{"class":105},"connection;     ",[84,495,496],{"class":90},"\u002F\u002F src\u002Fnetwork\u002Fconnection.rs\n",[84,498,499,501,503,505,507,510],{"class":86,"line":109},[84,500,190],{"class":97},[84,502,288],{"class":97},[84,504,291],{"class":101},[84,506,208],{"class":97},[84,508,509],{"class":105},"connection;   ",[84,511,512],{"class":90},"\u002F\u002F same, explicit\n",[18,514,516],{"id":515},"visibility","Visibility",[72,518,519],{"language":74},[76,520,522],{"className":78,"code":521,"language":74,"meta":80,"style":80},"pub fn public_fn() {}            \u002F\u002F visible everywhere\nfn private_fn() {}                \u002F\u002F visible only in this module\npub(crate) fn internal() {}       \u002F\u002F visible within this crate only\npub(super) fn for_parent() {}     \u002F\u002F visible in parent module\npub(in path) fn scoped() {}       \u002F\u002F visible in a specific module path\n",[34,523,524,540,554,577,598],{"__ignoreMap":80},[84,525,526,528,531,534,537],{"class":86,"line":87},[84,527,408],{"class":97},[84,529,530],{"class":97}," fn",[84,532,533],{"class":101}," public_fn",[84,535,536],{"class":105},"() {}            ",[84,538,539],{"class":90},"\u002F\u002F visible everywhere\n",[84,541,542,545,548,551],{"class":86,"line":94},[84,543,544],{"class":97},"fn",[84,546,547],{"class":101}," private_fn",[84,549,550],{"class":105},"() {}                ",[84,552,553],{"class":90},"\u002F\u002F visible only in this module\n",[84,555,556,558,561,563,566,568,571,574],{"class":86,"line":109},[84,557,408],{"class":97},[84,559,560],{"class":105},"(",[84,562,445],{"class":97},[84,564,565],{"class":105},") ",[84,567,544],{"class":97},[84,569,570],{"class":101}," internal",[84,572,573],{"class":105},"() {}       ",[84,575,576],{"class":90},"\u002F\u002F visible within this crate only\n",[84,578,579,581,583,585,587,589,592,595],{"class":86,"line":120},[84,580,408],{"class":97},[84,582,560],{"class":105},[84,584,450],{"class":237},[84,586,565],{"class":105},[84,588,544],{"class":97},[84,590,591],{"class":101}," for_parent",[84,593,594],{"class":105},"() {}     ",[84,596,597],{"class":90},"\u002F\u002F visible in parent module\n",[84,599,600,602,604,607,610,612,615,617],{"class":86,"line":134},[84,601,408],{"class":97},[84,603,560],{"class":105},[84,605,606],{"class":97},"in",[84,608,609],{"class":105}," path) ",[84,611,544],{"class":97},[84,613,614],{"class":101}," scoped",[84,616,573],{"class":105},[84,618,619],{"class":90},"\u002F\u002F visible in a specific module path\n",[14,621,622],{},"Fields and variants have their own visibility:",[72,624,625],{"language":74},[76,626,628],{"className":78,"code":627,"language":74,"meta":80,"style":80},"pub struct User {\n    pub name: String,\n    email: String,       \u002F\u002F private — only this module can construct\u002Fmodify\n}\n",[34,629,630,642,658,673],{"__ignoreMap":80},[84,631,632,634,637,640],{"class":86,"line":87},[84,633,408],{"class":97},[84,635,636],{"class":97}," struct",[84,638,639],{"class":101}," User",[84,641,117],{"class":105},[84,643,644,646,649,652,655],{"class":86,"line":94},[84,645,123],{"class":97},[84,647,648],{"class":105}," name",[84,650,651],{"class":97},":",[84,653,654],{"class":101}," String",[84,656,657],{"class":105},",\n",[84,659,660,663,665,667,670],{"class":86,"line":109},[84,661,662],{"class":105},"    email",[84,664,651],{"class":97},[84,666,654],{"class":101},[84,668,669],{"class":105},",       ",[84,671,672],{"class":90},"\u002F\u002F private — only this module can construct\u002Fmodify\n",[84,674,675],{"class":86,"line":120},[84,676,149],{"class":105},[14,678,679],{},"Enums' variants inherit the enum's visibility by default; you can override per-variant.",[18,681,683],{"id":682},"struct-visibility","Struct Visibility",[14,685,686,687,689],{},"A struct can be ",[34,688,408],{}," but have private fields — external code can't construct it with literal syntax or access private fields, but can use it via methods. This is how newtypes preserve invariants.",[18,691,693],{"id":692},"module-path-items","Module Path Items",[23,695,696,699,702,705,708,713],{},[26,697,698],{},"Modules",[26,700,701],{},"Functions",[26,703,704],{},"Structs\u002FEnums\u002FTypes",[26,706,707],{},"Constants\u002FStatics",[26,709,710,712],{},[34,711,190],{}," statements",[26,714,715,716,719,720,722],{},"Macros (via ",[34,717,718],{},"macro_rules!"," and ",[34,721,390],{},")",[18,724,726],{"id":725},"submodules-and-privacy","Submodules and Privacy",[14,728,729,730,732],{},"A child module can access anything in its parent (privacy is per-module-tree, with ",[34,731,408],{}," opening it up). Children can use private items of parents and ancestors.",[18,734,736,738,739],{"id":735},"pub-items-and-dochidden",[34,737,408],{}," Items and ",[34,740,741],{},"#[doc(hidden)]",[14,743,744,746,747,749],{},[34,745,741],{}," hides an item from docs while keeping it ",[34,748,408],{}," (used for internal macros or re-exports you don't want users to call directly).",[18,751,753],{"id":752},"crates-within-a-package","Crates Within a Package",[72,755,757],{"language":756},"toml",[76,758,761],{"className":759,"code":760,"language":756,"meta":80,"style":80},"language-toml shiki shiki-themes github-light github-dark","# Cargo.toml\n[lib]\nname = \"my_lib\"\npath = \"src\u002Flib.rs\"\n\n[[bin]]\nname = \"my_app\"\npath = \"src\u002Fmain.rs\"\n",[34,762,763,768,773,778,783,789,794,800],{"__ignoreMap":80},[84,764,765],{"class":86,"line":87},[84,766,767],{},"# Cargo.toml\n",[84,769,770],{"class":86,"line":94},[84,771,772],{},"[lib]\n",[84,774,775],{"class":86,"line":109},[84,776,777],{},"name = \"my_lib\"\n",[84,779,780],{"class":86,"line":120},[84,781,782],{},"path = \"src\u002Flib.rs\"\n",[84,784,785],{"class":86,"line":134},[84,786,788],{"emptyLinePlaceholder":787},true,"\n",[84,790,791],{"class":86,"line":146},[84,792,793],{},"[[bin]]\n",[84,795,797],{"class":86,"line":796},7,[84,798,799],{},"name = \"my_app\"\n",[84,801,803],{"class":86,"line":802},8,[84,804,805],{},"path = \"src\u002Fmain.rs\"\n",[14,807,808,809,812],{},"A package can have many binaries and at most one library. Binaries can use the library via ",[34,810,811],{},"use my_lib::...",".",[18,814,816],{"id":815},"external-crates","External Crates",[72,818,819],{"language":756},[76,820,822],{"className":759,"code":821,"language":756,"meta":80,"style":80},"# Cargo.toml\n[dependencies]\nserde = \"1.0\"\n",[34,823,824,828,833],{"__ignoreMap":80},[84,825,826],{"class":86,"line":87},[84,827,767],{},[84,829,830],{"class":86,"line":94},[84,831,832],{},"[dependencies]\n",[84,834,835],{"class":86,"line":109},[84,836,837],{},"serde = \"1.0\"\n",[72,839,840],{"language":74},[76,841,843],{"className":78,"code":842,"language":74,"meta":80,"style":80},"use serde::Serialize;     \u002F\u002F external crates are in the extern prelude\n",[34,844,845],{"__ignoreMap":80},[84,846,847,849,852,854,857,860],{"class":86,"line":87},[84,848,190],{"class":97},[84,850,851],{"class":101}," serde",[84,853,208],{"class":97},[84,855,856],{"class":101},"Serialize",[84,858,859],{"class":105},";     ",[84,861,862],{"class":90},"\u002F\u002F external crates are in the extern prelude\n",[14,864,865,866,869,870,872],{},"In edition 2018+, you don't need ",[34,867,868],{},"extern crate serde;"," — ",[34,871,190],{}," finds it.",[18,874,876],{"id":875},"workspaces","Workspaces",[72,878,879],{"language":756},[76,880,882],{"className":759,"code":881,"language":756,"meta":80,"style":80},"# Cargo.toml\n[workspace]\nmembers = [\"crates\u002Fapi\", \"crates\u002Fcli\", \"crates\u002Fcore\"]\n",[34,883,884,888,893],{"__ignoreMap":80},[84,885,886],{"class":86,"line":87},[84,887,767],{},[84,889,890],{"class":86,"line":94},[84,891,892],{},"[workspace]\n",[84,894,895],{"class":86,"line":109},[84,896,897],{},"members = [\"crates\u002Fapi\", \"crates\u002Fcli\", \"crates\u002Fcore\"]\n",[14,899,900,901,904,905,719,908,911],{},"Members can depend on each other via ",[34,902,903],{},"path = \"..\u002Fcore\"",". Shared ",[34,906,907],{},"Cargo.lock",[34,909,910],{},"target\u002F"," directory.",[18,913,915],{"id":914},"macros-across-modules","Macros Across Modules",[14,917,918,920,921,924],{},[34,919,718],{}," macros need ",[34,922,923],{},"#[macro_export]"," to be used outside their defining module:",[72,926,927],{"language":74},[76,928,930],{"className":78,"code":929,"language":74,"meta":80,"style":80},"#[macro_export]\nmacro_rules! my_macro { \u002F* ... *\u002F }\n",[34,931,932,937],{"__ignoreMap":80},[84,933,934],{"class":86,"line":87},[84,935,936],{"class":105},"#[macro_export]\n",[84,938,939,941,944,947,950],{"class":86,"line":94},[84,940,718],{"class":101},[84,942,943],{"class":101}," my_macro",[84,945,946],{"class":105}," { ",[84,948,949],{"class":90},"\u002F* ... *\u002F",[84,951,952],{"class":105}," }\n",[14,954,955,956,959],{},"They're exported at the crate root. Use ",[34,957,958],{},"pub use my_macro;"," to re-export.",[18,961,963],{"id":962},"module-organization-patterns","Module Organization Patterns",[331,965,967],{"id":966},"library-binaries","Library + Binaries",[76,969,972],{"className":970,"code":971,"language":173},[171],"my_project\u002F\n├── Cargo.toml\n├── src\u002F\n│   ├── lib.rs       # public API\n│   └── bin\u002F\n│       ├── server.rs\n│       └── client.rs\n",[34,973,971],{"__ignoreMap":80},[331,975,977],{"id":976},"feature-gated-modules","Feature-Gated Modules",[72,979,980],{"language":74},[76,981,983],{"className":78,"code":982,"language":74,"meta":80,"style":80},"#[cfg(feature = \"json\")]\npub mod json;\n",[34,984,985,1000],{"__ignoreMap":80},[84,986,987,990,993,997],{"class":86,"line":87},[84,988,989],{"class":105},"#[cfg(feature ",[84,991,992],{"class":97},"=",[84,994,996],{"class":995},"sJ6F3"," \"json\"",[84,998,999],{"class":105},")]\n",[84,1001,1002,1004,1006,1009],{"class":86,"line":94},[84,1003,408],{"class":97},[84,1005,126],{"class":97},[84,1007,1008],{"class":101}," json",[84,1010,106],{"class":105},[331,1012,1014],{"id":1013},"tests-inline-and-separate","Tests Inline and Separate",[72,1016,1017],{"language":74},[76,1018,1020],{"className":78,"code":1019,"language":74,"meta":80,"style":80},"\u002F\u002F src\u002Flib.rs\npub fn add(a: i32, b: i32) -> i32 { a + b }\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n    #[test]\n    fn test_add() { assert_eq!(add(1, 2), 3); }\n}\n",[34,1021,1022,1026,1066,1070,1075,1084,1095,1100,1138],{"__ignoreMap":80},[84,1023,1024],{"class":86,"line":87},[84,1025,91],{"class":90},[84,1027,1028,1030,1032,1035,1038,1040,1043,1046,1048,1050,1052,1055,1057,1060,1063],{"class":86,"line":94},[84,1029,408],{"class":97},[84,1031,530],{"class":97},[84,1033,1034],{"class":101}," add",[84,1036,1037],{"class":105},"(a",[84,1039,651],{"class":97},[84,1041,1042],{"class":101}," i32",[84,1044,1045],{"class":105},", b",[84,1047,651],{"class":97},[84,1049,1042],{"class":101},[84,1051,565],{"class":105},[84,1053,1054],{"class":97},"->",[84,1056,1042],{"class":101},[84,1058,1059],{"class":105}," { a ",[84,1061,1062],{"class":97},"+",[84,1064,1065],{"class":105}," b }\n",[84,1067,1068],{"class":86,"line":109},[84,1069,788],{"emptyLinePlaceholder":787},[84,1071,1072],{"class":86,"line":120},[84,1073,1074],{"class":105},"#[cfg(test)]\n",[84,1076,1077,1079,1082],{"class":86,"line":134},[84,1078,98],{"class":97},[84,1080,1081],{"class":101}," tests",[84,1083,117],{"class":105},[84,1085,1086,1089,1091,1093],{"class":86,"line":146},[84,1087,1088],{"class":97},"    use",[84,1090,306],{"class":237},[84,1092,359],{"class":97},[84,1094,106],{"class":105},[84,1096,1097],{"class":86,"line":796},[84,1098,1099],{"class":105},"    #[test]\n",[84,1101,1102,1105,1108,1111,1114,1116,1119,1121,1124,1126,1129,1132,1135],{"class":86,"line":802},[84,1103,1104],{"class":97},"    fn",[84,1106,1107],{"class":101}," test_add",[84,1109,1110],{"class":105},"() { ",[84,1112,1113],{"class":101},"assert_eq!",[84,1115,560],{"class":105},[84,1117,1118],{"class":101},"add",[84,1120,560],{"class":105},[84,1122,1123],{"class":237},"1",[84,1125,241],{"class":105},[84,1127,1128],{"class":237},"2",[84,1130,1131],{"class":105},"), ",[84,1133,1134],{"class":237},"3",[84,1136,1137],{"class":105},"); }\n",[84,1139,1141],{"class":86,"line":1140},9,[84,1142,149],{"class":105},[14,1144,1145,1146,1149],{},"Integration tests live in ",[34,1147,1148],{},"tests\u002F"," as separate crate:",[76,1151,1154],{"className":1152,"code":1153,"language":173},[171],"tests\u002F\n└── integration.rs\n",[34,1155,1153],{"__ignoreMap":80},[18,1157,1159],{"id":1158},"edge-cases","Edge Cases",[23,1161,1162,1179,1187,1200,1208,1221,1229,1238],{},[26,1163,1164,1169,1170,1173,1174,1178],{},[29,1165,1166,1168],{},[34,1167,408],{}," doesn't propagate to ancestors",": a ",[34,1171,1172],{},"pub mod"," is public ",[1175,1176,1177],"em",{},"if its parent is also accessible",". Privacy is layered.",[26,1180,1181,1186],{},[29,1182,1183,1185],{},[34,1184,390],{}," ambiguity",": re-exporting two items with the same name into the same scope is an error.",[26,1188,1189,1192,1193,719,1196,1199],{},[29,1190,1191],{},"Module path and item name conflicts",": ",[34,1194,1195],{},"mod foo;",[34,1197,1198],{},"use crate::foo;"," are different things.",[26,1201,1202,1207],{},[29,1203,1204],{},[34,1205,1206],{},"#[non_exhaustive]"," prevents exhaustive construction outside the crate.",[26,1209,1210,1216,1217,1220],{},[29,1211,1212,1213,1215],{},"Private items in ",[34,1214,408],{}," functions",": a public function can't have private types in its signature (e.g., ",[34,1218,1219],{},"pub fn get() -> PrivateType"," is an error — leaks private type).",[26,1222,1223,1228],{},[29,1224,1225],{},[34,1226,1227],{},"extern crate self as foo;",": lets you refer to your own crate by name (rare).",[26,1230,1231,1237],{},[29,1232,1233,1234],{},"Hidden ",[34,1235,1236],{},"mod.rs",": still works but is discouraged; the new layout is cleaner.",[26,1239,1240,1245,1246,1249],{},[29,1241,1242,1244],{},[34,1243,390],{}," for preludes",": many crates expose ",[34,1247,1248],{},"pub mod prelude { pub use ...; }"," for one-line imports.",[18,1251,1253],{"id":1252},"best-practices","Best Practices",[23,1255,1256,1259,1262,1268,1274,1280],{},[26,1257,1258],{},"One responsibility per module.",[26,1260,1261],{},"Hide internals; expose minimal API.",[26,1263,1264,1265,1267],{},"Use ",[34,1266,390],{}," to flatten the surface.",[26,1269,1270,1271,51],{},"Test files live alongside source (",[34,1272,1273],{},"#[cfg(test)] mod tests",[26,1275,1276,1277,51],{},"Re-export crates you wrap so users don't need direct deps (",[34,1278,1279],{},"pub use serde;",[26,1281,1282],{},"Don't go too deep — 3 levels is usually enough.",[18,1284,1286],{"id":1285},"summary","Summary",[14,1288,1289,1290,1292,1293,1295,1296,47,1298,47,1300,1302,1303,1305],{},"Modules organize code; ",[34,1291,408],{}," controls visibility; ",[34,1294,190],{}," brings items into scope; ",[34,1297,445],{},[34,1299,450],{},[34,1301,238],{}," form absolute\u002Frelative paths; ",[34,1304,390],{}," re-exports flatten APIs. Files and modules are connected but distinct — the 2018 edition simplified the file\u002Fmodule mapping.",[14,1307,1308],{},"Next: Cargo features, build scripts, and release engineering.",[1310,1311,1312],"style",{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .github-dark .shiki span {color: var(--shiki-github-dark);background: var(--shiki-github-dark-bg);font-style: var(--shiki-github-dark-font-style);font-weight: var(--shiki-github-dark-font-weight);text-decoration: var(--shiki-github-dark-text-decoration);}html.github-dark .shiki span {color: var(--shiki-github-dark);background: var(--shiki-github-dark-bg);font-style: var(--shiki-github-dark-font-style);font-weight: var(--shiki-github-dark-font-weight);text-decoration: var(--shiki-github-dark-text-decoration);}html pre.shiki code .sdCPZ, html code.shiki .sdCPZ{--shiki-default:#6A737D;--shiki-github-dark:#6A737D}html pre.shiki code .svdQ7, html code.shiki .svdQ7{--shiki-default:#D73A49;--shiki-github-dark:#F97583}html pre.shiki code .sIsaT, html code.shiki .sIsaT{--shiki-default:#6F42C1;--shiki-github-dark:#B392F0}html pre.shiki code .ssxIu, html code.shiki .ssxIu{--shiki-default:#24292E;--shiki-github-dark:#E1E4E8}html pre.shiki code .snvgF, html code.shiki .snvgF{--shiki-default:#005CC5;--shiki-github-dark:#79B8FF}html pre.shiki code .sJ6F3, html code.shiki .sJ6F3{--shiki-default:#032F62;--shiki-github-dark:#9ECBFF}",{"title":80,"searchDepth":94,"depth":94,"links":1314},[1315,1316,1317,1318,1322,1324,1326,1327,1328,1329,1330,1332,1333,1334,1335,1336,1341,1342,1343],{"id":20,"depth":94,"text":21},{"id":69,"depth":94,"text":70},{"id":166,"depth":94,"text":167},{"id":187,"depth":94,"text":1319,"children":1320},"use — Importing",[1321],{"id":333,"depth":109,"text":334},{"id":387,"depth":94,"text":1323},"pub use — Re-exports",{"id":441,"depth":94,"text":1325},"Paths and crate, self, super",{"id":515,"depth":94,"text":516},{"id":682,"depth":94,"text":683},{"id":692,"depth":94,"text":693},{"id":725,"depth":94,"text":726},{"id":735,"depth":94,"text":1331},"pub Items and #[doc(hidden)]",{"id":752,"depth":94,"text":753},{"id":815,"depth":94,"text":816},{"id":875,"depth":94,"text":876},{"id":914,"depth":94,"text":915},{"id":962,"depth":94,"text":963,"children":1337},[1338,1339,1340],{"id":966,"depth":109,"text":967},{"id":976,"depth":109,"text":977},{"id":1013,"depth":109,"text":1014},{"id":1158,"depth":94,"text":1159},{"id":1252,"depth":94,"text":1253},{"id":1285,"depth":94,"text":1286},"md",{},"\u002Frust\u002F20-modules-and-crates",{"title":5,"description":16},"rust\u002F20-modules-and-crates","LHSOD4UfosgDG8Aq8kaNxaQOZrk7RFuKd4vXdg845xE",1785944093250]