[{"data":1,"prerenderedAt":1346},["ShallowReactive",2],{"page-\u002Frust\u002F03-variables-and-mutability":3},{"id":4,"title":5,"body":6,"description":31,"extension":1340,"meta":1341,"navigation":204,"path":1342,"seo":1343,"stem":1344,"__hash__":1345},"content\u002Frust\u002F03-variables-and-mutability.md","03 — Variables & Mutability",{"type":7,"value":8,"toc":1322},"minimark",[9,13,22,105,118,122,137,276,283,337,343,347,376,411,499,505,509,563,588,592,701,704,799,805,810,1000,1004,1092,1102,1106,1245,1251,1254,1303,1307,1318],[10,11,5],"h1",{"id":12},"_03-variables-mutability",[14,15,17,21],"h2",{"id":16},"let-and-immutability-by-default",[18,19,20],"code",{},"let"," and Immutability by Default",[23,24,26],"code-wrapper",{"language":25},"rust",[27,28,32],"pre",{"className":29,"code":30,"language":25,"meta":31,"style":31},"language-rust shiki shiki-themes github-light github-dark","let x = 5;          \u002F\u002F immutable\nlet mut y = 5;      \u002F\u002F mutable\ny += 1;\n\u002F\u002F x = 6;           \u002F\u002F ERROR: cannot assign twice to immutable variable\n","",[18,33,34,60,81,96],{"__ignoreMap":31},[35,36,39,42,46,49,53,56],"span",{"class":37,"line":38},"line",1,[35,40,20],{"class":41},"svdQ7",[35,43,45],{"class":44},"ssxIu"," x ",[35,47,48],{"class":41},"=",[35,50,52],{"class":51},"snvgF"," 5",[35,54,55],{"class":44},";          ",[35,57,59],{"class":58},"sdCPZ","\u002F\u002F immutable\n",[35,61,63,65,68,71,73,75,78],{"class":37,"line":62},2,[35,64,20],{"class":41},[35,66,67],{"class":41}," mut",[35,69,70],{"class":44}," y ",[35,72,48],{"class":41},[35,74,52],{"class":51},[35,76,77],{"class":44},";      ",[35,79,80],{"class":58},"\u002F\u002F mutable\n",[35,82,84,87,90,93],{"class":37,"line":83},3,[35,85,86],{"class":44},"y ",[35,88,89],{"class":41},"+=",[35,91,92],{"class":51}," 1",[35,94,95],{"class":44},";\n",[35,97,99,102],{"class":37,"line":98},4,[35,100,101],{"class":58},"\u002F\u002F x = 6;",[35,103,104],{"class":58},"           \u002F\u002F ERROR: cannot assign twice to immutable variable\n",[106,107,108,109,113,114,117],"p",{},"Rust variables are ",[110,111,112],"strong",{},"immutable by default",". You must opt into mutation with ",[18,115,116],{},"mut",". This isn't a philosophical stance — it lets the compiler reason about aliasing for ownership and concurrency guarantees.",[14,119,121],{"id":120},"shadowing","Shadowing",[106,123,124,125,127,128,132,133,136],{},"A new ",[18,126,20],{}," with the same name ",[129,130,131],"em",{},"shadows"," the previous binding. The old value still gets dropped at end of scope; shadowing creates a ",[110,134,135],{},"new"," binding (possibly a new type).",[23,138,139],{"language":25},[27,140,142],{"className":29,"code":141,"language":25,"meta":31,"style":31},"let x = 5;\nlet x = x + 1;          \u002F\u002F shadows, same type\nlet x = x.to_string();  \u002F\u002F shadows with new type — totally fine\n\n{\n    let x = x * 2;      \u002F\u002F shadows inside block\n    println!(\"{x}\");    \u002F\u002F 12\n}\nprintln!(\"{x}\");        \u002F\u002F 6 (block shadow gone)\n",[18,143,144,156,176,200,206,212,235,254,260],{"__ignoreMap":31},[35,145,146,148,150,152,154],{"class":37,"line":38},[35,147,20],{"class":41},[35,149,45],{"class":44},[35,151,48],{"class":41},[35,153,52],{"class":51},[35,155,95],{"class":44},[35,157,158,160,162,164,166,169,171,173],{"class":37,"line":62},[35,159,20],{"class":41},[35,161,45],{"class":44},[35,163,48],{"class":41},[35,165,45],{"class":44},[35,167,168],{"class":41},"+",[35,170,92],{"class":51},[35,172,55],{"class":44},[35,174,175],{"class":58},"\u002F\u002F shadows, same type\n",[35,177,178,180,182,184,187,190,194,197],{"class":37,"line":83},[35,179,20],{"class":41},[35,181,45],{"class":44},[35,183,48],{"class":41},[35,185,186],{"class":44}," x",[35,188,189],{"class":41},".",[35,191,193],{"class":192},"sIsaT","to_string",[35,195,196],{"class":44},"();  ",[35,198,199],{"class":58},"\u002F\u002F shadows with new type — totally fine\n",[35,201,202],{"class":37,"line":98},[35,203,205],{"emptyLinePlaceholder":204},true,"\n",[35,207,209],{"class":37,"line":208},5,[35,210,211],{"class":44},"{\n",[35,213,215,218,220,222,224,227,230,232],{"class":37,"line":214},6,[35,216,217],{"class":41},"    let",[35,219,45],{"class":44},[35,221,48],{"class":41},[35,223,45],{"class":44},[35,225,226],{"class":41},"*",[35,228,229],{"class":51}," 2",[35,231,77],{"class":44},[35,233,234],{"class":58},"\u002F\u002F shadows inside block\n",[35,236,238,241,244,248,251],{"class":37,"line":237},7,[35,239,240],{"class":192},"    println!",[35,242,243],{"class":44},"(",[35,245,247],{"class":246},"sJ6F3","\"{x}\"",[35,249,250],{"class":44},");    ",[35,252,253],{"class":58},"\u002F\u002F 12\n",[35,255,257],{"class":37,"line":256},8,[35,258,259],{"class":44},"}\n",[35,261,263,266,268,270,273],{"class":37,"line":262},9,[35,264,265],{"class":192},"println!",[35,267,243],{"class":44},[35,269,247],{"class":246},[35,271,272],{"class":44},");        ",[35,274,275],{"class":58},"\u002F\u002F 6 (block shadow gone)\n",[277,278,280,281],"h3",{"id":279},"shadowing-vs-mut","Shadowing vs ",[18,282,116],{},[284,285,286,302],"table",{},[287,288,289],"thead",{},[290,291,292,296,298],"tr",{},[293,294,295],"th",{},"Feature",[293,297,121],{},[293,299,300],{},[18,301,116],{},[303,304,305,317,326],"tbody",{},[290,306,307,311,314],{},[308,309,310],"td",{},"New binding?",[308,312,313],{},"Yes",[308,315,316],{},"No",[290,318,319,322,324],{},[308,320,321],{},"Can change type?",[308,323,313],{},[308,325,316],{},[290,327,328,331,334],{},[308,329,330],{},"Requires initialization at declaration?",[308,332,333],{},"No (can be uninit then assign)",[308,335,336],{},"Yes (must assign)",[106,338,339,340,342],{},"Use shadowing to transform a value into a different type\u002Fshape; use ",[18,341,116],{}," to evolve one value.",[14,344,346],{"id":345},"constants","Constants",[23,348,349],{"language":25},[27,350,352],{"className":29,"code":351,"language":25,"meta":31,"style":31},"const MAX_POINTS: u32 = 100_000;\n",[18,353,354],{"__ignoreMap":31},[35,355,356,359,362,365,368,371,374],{"class":37,"line":38},[35,357,358],{"class":41},"const",[35,360,361],{"class":51}," MAX_POINTS",[35,363,364],{"class":41},":",[35,366,367],{"class":192}," u32",[35,369,370],{"class":41}," =",[35,372,373],{"class":51}," 100_000",[35,375,95],{"class":44},[377,378,379,385,388,394,397,400],"ul",{},[380,381,382,384],"li",{},[18,383,358],{}," is evaluated at compile time (must be a constant expression).",[380,386,387],{},"Always annotated with a type.",[380,389,390,391,189],{},"Conventionally ",[18,392,393],{},"SCREAMING_SNAKE_CASE",[380,395,396],{},"Inlined everywhere; no fixed memory address.",[380,398,399],{},"Can be declared in any scope, including module\u002Fglobal.",[380,401,402,403,405,406,408,409,189],{},"Cannot shadow ",[18,404,116],{}," (they're always immutable); a ",[18,407,358],{}," cannot be ",[18,410,116],{},[23,412,413],{"language":25},[27,414,416],{"className":29,"code":415,"language":25,"meta":31,"style":31},"const FACTOR: f64 = 1.5;\nconst fn double(x: i32) -> i32 { x * 2 }   \u002F\u002F const fn: callable in const context\nconst ANSWER: i32 = double(21);\n",[18,417,418,437,476],{"__ignoreMap":31},[35,419,420,422,425,427,430,432,435],{"class":37,"line":38},[35,421,358],{"class":41},[35,423,424],{"class":51}," FACTOR",[35,426,364],{"class":41},[35,428,429],{"class":192}," f64",[35,431,370],{"class":41},[35,433,434],{"class":51}," 1.5",[35,436,95],{"class":44},[35,438,439,441,444,447,450,452,455,458,461,463,466,468,470,473],{"class":37,"line":62},[35,440,358],{"class":41},[35,442,443],{"class":41}," fn",[35,445,446],{"class":192}," double",[35,448,449],{"class":44},"(x",[35,451,364],{"class":41},[35,453,454],{"class":192}," i32",[35,456,457],{"class":44},") ",[35,459,460],{"class":41},"->",[35,462,454],{"class":192},[35,464,465],{"class":44}," { x ",[35,467,226],{"class":41},[35,469,229],{"class":51},[35,471,472],{"class":44}," }   ",[35,474,475],{"class":58},"\u002F\u002F const fn: callable in const context\n",[35,477,478,480,483,485,487,489,491,493,496],{"class":37,"line":83},[35,479,358],{"class":41},[35,481,482],{"class":51}," ANSWER",[35,484,364],{"class":41},[35,486,454],{"class":192},[35,488,370],{"class":41},[35,490,446],{"class":192},[35,492,243],{"class":44},[35,494,495],{"class":51},"21",[35,497,498],{"class":44},");\n",[106,500,501,504],{},[18,502,503],{},"const fn"," allows a restricted subset of Rust at compile time (no heap, limited control flow historically; improving each release).",[14,506,508],{"id":507},"statics","Statics",[23,510,511],{"language":25},[27,512,514],{"className":29,"code":513,"language":25,"meta":31,"style":31},"static LANGUAGE: &str = \"Rust\";\nstatic mut COUNTER: u32 = 0;   \u002F\u002F mutable static — unsafe to read\u002Fwrite\n",[18,515,516,539],{"__ignoreMap":31},[35,517,518,521,524,526,529,532,534,537],{"class":37,"line":38},[35,519,520],{"class":41},"static",[35,522,523],{"class":51}," LANGUAGE",[35,525,364],{"class":41},[35,527,528],{"class":41}," &",[35,530,531],{"class":192},"str",[35,533,370],{"class":41},[35,535,536],{"class":246}," \"Rust\"",[35,538,95],{"class":44},[35,540,541,543,545,548,550,552,554,557,560],{"class":37,"line":62},[35,542,520],{"class":41},[35,544,67],{"class":41},[35,546,547],{"class":51}," COUNTER",[35,549,364],{"class":41},[35,551,367],{"class":192},[35,553,370],{"class":41},[35,555,556],{"class":51}," 0",[35,558,559],{"class":44},";   ",[35,561,562],{"class":58},"\u002F\u002F mutable static — unsafe to read\u002Fwrite\n",[377,564,565,568,578],{},[380,566,567],{},"Have a fixed memory address for the program's lifetime.",[380,569,570,573,574,577],{},[18,571,572],{},"static mut"," requires ",[18,575,576],{},"unsafe"," to access (no synchronization).",[380,579,580,581,584,585,587],{},"Use atomics (",[18,582,583],{},"std::sync::atomic",") instead of ",[18,586,572],{}," for counters.",[14,589,591],{"id":590},"type-inference","Type Inference",[23,593,594],{"language":25},[27,595,597],{"className":29,"code":596,"language":25,"meta":31,"style":31},"let v = vec![1, 2, 3];      \u002F\u002F Vec\u003Ci32>\nlet s = \"hi\";               \u002F\u002F &str\nlet n = 1.0;                \u002F\u002F f64 (default float)\nlet i = 1;                  \u002F\u002F i32 (default integer)\nlet b = true;\n",[18,598,599,634,652,670,687],{"__ignoreMap":31},[35,600,601,603,606,608,611,614,617,620,623,625,628,631],{"class":37,"line":38},[35,602,20],{"class":41},[35,604,605],{"class":44}," v ",[35,607,48],{"class":41},[35,609,610],{"class":192}," vec!",[35,612,613],{"class":44},"[",[35,615,616],{"class":51},"1",[35,618,619],{"class":44},", ",[35,621,622],{"class":51},"2",[35,624,619],{"class":44},[35,626,627],{"class":51},"3",[35,629,630],{"class":44},"];      ",[35,632,633],{"class":58},"\u002F\u002F Vec\u003Ci32>\n",[35,635,636,638,641,643,646,649],{"class":37,"line":62},[35,637,20],{"class":41},[35,639,640],{"class":44}," s ",[35,642,48],{"class":41},[35,644,645],{"class":246}," \"hi\"",[35,647,648],{"class":44},";               ",[35,650,651],{"class":58},"\u002F\u002F &str\n",[35,653,654,656,659,661,664,667],{"class":37,"line":83},[35,655,20],{"class":41},[35,657,658],{"class":44}," n ",[35,660,48],{"class":41},[35,662,663],{"class":51}," 1.0",[35,665,666],{"class":44},";                ",[35,668,669],{"class":58},"\u002F\u002F f64 (default float)\n",[35,671,672,674,677,679,681,684],{"class":37,"line":98},[35,673,20],{"class":41},[35,675,676],{"class":44}," i ",[35,678,48],{"class":41},[35,680,92],{"class":51},[35,682,683],{"class":44},";                  ",[35,685,686],{"class":58},"\u002F\u002F i32 (default integer)\n",[35,688,689,691,694,696,699],{"class":37,"line":208},[35,690,20],{"class":41},[35,692,693],{"class":44}," b ",[35,695,48],{"class":41},[35,697,698],{"class":51}," true",[35,700,95],{"class":44},[106,702,703],{},"When the type can't be inferred, add an annotation:",[23,705,706],{"language":25},[27,707,709],{"className":29,"code":708,"language":25,"meta":31,"style":31},"let mut v: Vec\u003Cu8> = Vec::new();\nlet n: u64 = 42;\nlet parsed = \"42\".parse::\u003Ci32>().unwrap();\n",[18,710,711,746,765],{"__ignoreMap":31},[35,712,713,715,717,720,722,725,728,731,734,736,738,741,743],{"class":37,"line":38},[35,714,20],{"class":41},[35,716,67],{"class":41},[35,718,719],{"class":44}," v",[35,721,364],{"class":41},[35,723,724],{"class":192}," Vec",[35,726,727],{"class":44},"\u003C",[35,729,730],{"class":192},"u8",[35,732,733],{"class":44},"> ",[35,735,48],{"class":41},[35,737,724],{"class":192},[35,739,740],{"class":41},"::",[35,742,135],{"class":192},[35,744,745],{"class":44},"();\n",[35,747,748,750,753,755,758,760,763],{"class":37,"line":62},[35,749,20],{"class":41},[35,751,752],{"class":44}," n",[35,754,364],{"class":41},[35,756,757],{"class":192}," u64",[35,759,370],{"class":41},[35,761,762],{"class":51}," 42",[35,764,95],{"class":44},[35,766,767,769,772,774,777,779,782,784,786,789,792,794,797],{"class":37,"line":83},[35,768,20],{"class":41},[35,770,771],{"class":44}," parsed ",[35,773,48],{"class":41},[35,775,776],{"class":246}," \"42\"",[35,778,189],{"class":41},[35,780,781],{"class":192},"parse",[35,783,740],{"class":41},[35,785,727],{"class":44},[35,787,788],{"class":192},"i32",[35,790,791],{"class":44},">()",[35,793,189],{"class":41},[35,795,796],{"class":192},"unwrap",[35,798,745],{"class":44},[14,800,802,804],{"id":801},"let-patterns-destructuring",[18,803,20],{}," Patterns (Destructuring)",[106,806,807,809],{},[18,808,20],{}," is a pattern, not just a binding:",[23,811,812],{"language":25},[27,813,815],{"className":29,"code":814,"language":25,"meta":31,"style":31},"let (a, b, c) = (1, 2, 3);\nlet [first, ..] = [1, 2, 3];        \u002F\u002F slice pattern (limited on stable)\nlet (x, ..) = (1, 2, 3, 4);         \u002F\u002F ignore rest\nlet Point { x, y } = point;          \u002F\u002F struct destructuring\nlet (Ok(v) | Err(v)) = result.map(|n| n + 1).map_err(|e| 0); \u002F\u002F or-pattern binding\n",[18,816,817,841,875,911,929],{"__ignoreMap":31},[35,818,819,821,824,826,829,831,833,835,837,839],{"class":37,"line":38},[35,820,20],{"class":41},[35,822,823],{"class":44}," (a, b, c) ",[35,825,48],{"class":41},[35,827,828],{"class":44}," (",[35,830,616],{"class":51},[35,832,619],{"class":44},[35,834,622],{"class":51},[35,836,619],{"class":44},[35,838,627],{"class":51},[35,840,498],{"class":44},[35,842,843,845,848,851,854,856,859,861,863,865,867,869,872],{"class":37,"line":62},[35,844,20],{"class":41},[35,846,847],{"class":44}," [first, ",[35,849,850],{"class":41},"..",[35,852,853],{"class":44},"] ",[35,855,48],{"class":41},[35,857,858],{"class":44}," [",[35,860,616],{"class":51},[35,862,619],{"class":44},[35,864,622],{"class":51},[35,866,619],{"class":44},[35,868,627],{"class":51},[35,870,871],{"class":44},"];        ",[35,873,874],{"class":58},"\u002F\u002F slice pattern (limited on stable)\n",[35,876,877,879,882,884,886,888,890,892,894,896,898,900,902,905,908],{"class":37,"line":83},[35,878,20],{"class":41},[35,880,881],{"class":44}," (x, ",[35,883,850],{"class":41},[35,885,457],{"class":44},[35,887,48],{"class":41},[35,889,828],{"class":44},[35,891,616],{"class":51},[35,893,619],{"class":44},[35,895,622],{"class":51},[35,897,619],{"class":44},[35,899,627],{"class":51},[35,901,619],{"class":44},[35,903,904],{"class":51},"4",[35,906,907],{"class":44},");         ",[35,909,910],{"class":58},"\u002F\u002F ignore rest\n",[35,912,913,915,918,921,923,926],{"class":37,"line":98},[35,914,20],{"class":41},[35,916,917],{"class":192}," Point",[35,919,920],{"class":44}," { x, y } ",[35,922,48],{"class":41},[35,924,925],{"class":44}," point;          ",[35,927,928],{"class":58},"\u002F\u002F struct destructuring\n",[35,930,931,933,935,938,941,944,947,950,952,955,957,960,962,964,967,969,971,973,975,978,980,983,985,987,990,992,994,997],{"class":37,"line":208},[35,932,20],{"class":41},[35,934,828],{"class":44},[35,936,937],{"class":192},"Ok",[35,939,940],{"class":44},"(v) ",[35,942,943],{"class":41},"|",[35,945,946],{"class":192}," Err",[35,948,949],{"class":44},"(v)) ",[35,951,48],{"class":41},[35,953,954],{"class":44}," result",[35,956,189],{"class":41},[35,958,959],{"class":192},"map",[35,961,243],{"class":44},[35,963,943],{"class":41},[35,965,966],{"class":44},"n",[35,968,943],{"class":41},[35,970,658],{"class":44},[35,972,168],{"class":41},[35,974,92],{"class":51},[35,976,977],{"class":44},")",[35,979,189],{"class":41},[35,981,982],{"class":192},"map_err",[35,984,243],{"class":44},[35,986,943],{"class":41},[35,988,989],{"class":44},"e",[35,991,943],{"class":41},[35,993,556],{"class":51},[35,995,996],{"class":44},"); ",[35,998,999],{"class":58},"\u002F\u002F or-pattern binding\n",[14,1001,1003],{"id":1002},"mutable-references-vs-mutable-variables","Mutable References vs Mutable Variables",[23,1005,1006],{"language":25},[27,1007,1009],{"className":29,"code":1008,"language":25,"meta":31,"style":31},"let mut v = vec![1, 2, 3];\nv.push(4);\n\nlet r = &mut v;     \u002F\u002F mutable reference (covered in Borrowing chapter)\nr.push(5);\n",[18,1010,1011,1038,1054,1058,1076],{"__ignoreMap":31},[35,1012,1013,1015,1017,1019,1021,1023,1025,1027,1029,1031,1033,1035],{"class":37,"line":38},[35,1014,20],{"class":41},[35,1016,67],{"class":41},[35,1018,605],{"class":44},[35,1020,48],{"class":41},[35,1022,610],{"class":192},[35,1024,613],{"class":44},[35,1026,616],{"class":51},[35,1028,619],{"class":44},[35,1030,622],{"class":51},[35,1032,619],{"class":44},[35,1034,627],{"class":51},[35,1036,1037],{"class":44},"];\n",[35,1039,1040,1043,1045,1048,1050,1052],{"class":37,"line":62},[35,1041,1042],{"class":44},"v",[35,1044,189],{"class":41},[35,1046,1047],{"class":192},"push",[35,1049,243],{"class":44},[35,1051,904],{"class":51},[35,1053,498],{"class":44},[35,1055,1056],{"class":37,"line":83},[35,1057,205],{"emptyLinePlaceholder":204},[35,1059,1060,1062,1065,1067,1070,1073],{"class":37,"line":98},[35,1061,20],{"class":41},[35,1063,1064],{"class":44}," r ",[35,1066,48],{"class":41},[35,1068,1069],{"class":41}," &mut",[35,1071,1072],{"class":44}," v;     ",[35,1074,1075],{"class":58},"\u002F\u002F mutable reference (covered in Borrowing chapter)\n",[35,1077,1078,1081,1083,1085,1087,1090],{"class":37,"line":208},[35,1079,1080],{"class":44},"r",[35,1082,189],{"class":41},[35,1084,1047],{"class":192},[35,1086,243],{"class":44},[35,1088,1089],{"class":51},"5",[35,1091,498],{"class":44},[106,1093,1094,1095,1098,1099,1101],{},"A ",[18,1096,1097],{},"&mut T"," requires the underlying binding to be ",[18,1100,116],{}," too (you can't take a mutable borrow of an immutable binding).",[14,1103,1105],{"id":1104},"edge-cases-pitfalls","Edge Cases & Pitfalls",[377,1107,1108,1127,1140,1152,1167,1199,1215,1225,1236],{},[380,1109,1110,1115,1116,1119,1120,1122,1123,1126],{},[110,1111,1112,1113],{},"Unused ",[18,1114,116],{},": ",[18,1117,1118],{},"warning: variable does not need to be mutable",". Fix by removing ",[18,1121,116],{}," or prefix ",[18,1124,1125],{},"_mut"," if intentional.",[380,1128,1129,1115,1132,1135,1136,1139],{},[110,1130,1131],{},"Unused variables",[18,1133,1134],{},"let _x = 5;"," (leading underscore) suppresses the warning; ",[18,1137,1138],{},"_"," itself drops the value immediately.",[380,1141,1142,1147,1148,1151],{},[110,1143,1144],{},[18,1145,1146],{},"let _ = expr;"," evaluates ",[18,1149,1150],{},"expr"," then immediately drops the result — useful for side effects.",[380,1153,1154,1157,1158,1161,1162,1164,1165,189],{},[110,1155,1156],{},"Capture in closures",": a closure capturing ",[18,1159,1160],{},"x"," immutably borrows; capturing mutably requires the variable to be ",[18,1163,116],{}," and the closure itself ",[18,1166,116],{},[380,1168,1169,1172,1173,619,1176,619,1179,1182,1183,1185,1186,1188,1189,1192,1193,1192,1196,189],{},[110,1170,1171],{},"Const generics \u002F types in const",": types like ",[18,1174,1175],{},"Vec",[18,1177,1178],{},"String",[18,1180,1181],{},"Box"," can't live in ",[18,1184,358],{}," context (no heap at compile time), but they can in ",[18,1187,520],{}," only via ",[18,1190,1191],{},"lazy_static","\u002F",[18,1194,1195],{},"once_cell",[18,1197,1198],{},"std::sync::OnceLock",[380,1200,1201,1115,1204,1207,1208,1211,1212,1214],{},[110,1202,1203],{},"Shadowing footgun",[18,1205,1206],{},"let x = something_that_panic();"," after ",[18,1209,1210],{},"let x = 5;"," — the first ",[18,1213,1160],{}," is shadowed and dropped at scope end, but the panic happens during init of the new binding.",[380,1216,1217,1220,1221,1224],{},[110,1218,1219],{},"Initialization required",": Rust has no \"uninitialized variable\" UB like C. ",[18,1222,1223],{},"let x: i32;"," followed by a read before any assignment is a compile error.",[380,1226,1227,1115,1232,1235],{},[110,1228,1229,1231],{},[18,1230,20],{}," chains (unstable)",[18,1233,1234],{},"let Some(x) = opt && x > 0"," — not stable; use explicit checks.",[380,1237,1238,1115,1241,1244],{},[110,1239,1240],{},"Tuples and unit",[18,1242,1243],{},"let () = some_fn();"," pattern-matches that the function returns unit; useful for \"I expect this to return nothing.\"",[14,1246,1248,1250],{"id":1247},"let-else-165",[18,1249,20],{},"-else (1.65+)",[106,1252,1253],{},"Diverge if a pattern doesn't match:",[23,1255,1256],{"language":25},[27,1257,1259],{"className":29,"code":1258,"language":25,"meta":31,"style":31},"let Some(x) = maybe_value else {\n    return; \u002F\u002F or panic!, break, continue, etc.\n};\n\u002F\u002F x is bound and in scope here\n",[18,1260,1261,1282,1293,1298],{"__ignoreMap":31},[35,1262,1263,1265,1268,1271,1273,1276,1279],{"class":37,"line":38},[35,1264,20],{"class":41},[35,1266,1267],{"class":192}," Some",[35,1269,1270],{"class":44},"(x) ",[35,1272,48],{"class":41},[35,1274,1275],{"class":44}," maybe_value ",[35,1277,1278],{"class":41},"else",[35,1280,1281],{"class":44}," {\n",[35,1283,1284,1287,1290],{"class":37,"line":62},[35,1285,1286],{"class":41},"    return",[35,1288,1289],{"class":44},"; ",[35,1291,1292],{"class":58},"\u002F\u002F or panic!, break, continue, etc.\n",[35,1294,1295],{"class":37,"line":83},[35,1296,1297],{"class":44},"};\n",[35,1299,1300],{"class":37,"line":98},[35,1301,1302],{"class":58},"\u002F\u002F x is bound and in scope here\n",[14,1304,1306],{"id":1305},"summary","Summary",[106,1308,1309,1310,1312,1313,1192,1315,1317],{},"Variables are immutable by default; use ",[18,1311,116],{}," for evolution, shadowing for transformation, ",[18,1314,358],{},[18,1316,520],{}," for compile-time\u002Fglobal values. Next: the full type system.",[1319,1320,1321],"style",{},"html pre.shiki code .svdQ7, html code.shiki .svdQ7{--shiki-default:#D73A49;--shiki-github-dark:#F97583}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 .sdCPZ, html code.shiki .sdCPZ{--shiki-default:#6A737D;--shiki-github-dark:#6A737D}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 .sIsaT, html code.shiki .sIsaT{--shiki-default:#6F42C1;--shiki-github-dark:#B392F0}html pre.shiki code .sJ6F3, html code.shiki .sJ6F3{--shiki-default:#032F62;--shiki-github-dark:#9ECBFF}",{"title":31,"searchDepth":62,"depth":62,"links":1323},[1324,1326,1330,1331,1332,1333,1335,1336,1337,1339],{"id":16,"depth":62,"text":1325},"let and Immutability by Default",{"id":120,"depth":62,"text":121,"children":1327},[1328],{"id":279,"depth":83,"text":1329},"Shadowing vs mut",{"id":345,"depth":62,"text":346},{"id":507,"depth":62,"text":508},{"id":590,"depth":62,"text":591},{"id":801,"depth":62,"text":1334},"let Patterns (Destructuring)",{"id":1002,"depth":62,"text":1003},{"id":1104,"depth":62,"text":1105},{"id":1247,"depth":62,"text":1338},"let-else (1.65+)",{"id":1305,"depth":62,"text":1306},"md",{},"\u002Frust\u002F03-variables-and-mutability",{"title":5,"description":31},"rust\u002F03-variables-and-mutability","_vAyjUUFvy6D5N2NZI4Usb5R7ETB4Sn3Lzc-1uvpGzQ",1785944093186]