[{"data":1,"prerenderedAt":572},["ShallowReactive",2],{"page-\u002Frust\u002F01-introduction-and-setup":3},{"id":4,"title":5,"body":6,"description":118,"extension":566,"meta":567,"navigation":166,"path":568,"seo":569,"stem":570,"__hash__":571},"content\u002Frust\u002F01-introduction-and-setup.md","01 — Introduction & Setup",{"type":7,"value":8,"toc":551},"minimark",[9,13,18,31,92,96,99,103,109,174,177,204,209,229,302,306,313,332,356,360,368,372,416,420,426,430,509,513,519,537,541,547],[10,11,5],"h1",{"id":12},"_01-introduction-setup",[14,15,17],"h2",{"id":16},"why-rust","Why Rust?",[19,20,21,22,26,27,30],"p",{},"Rust is a systems programming language that guarantees ",[23,24,25],"strong",{},"memory safety"," and ",[23,28,29],{},"thread safety"," without a garbage collector. It achieves this through a unique ownership model enforced at compile time. Key selling points:",[32,33,34,41,47,53,59,65],"ul",{},[35,36,37,40],"li",{},[23,38,39],{},"Performance",": comparable to C\u002FC++; no runtime, no GC.",[35,42,43,46],{},[23,44,45],{},"Memory safety",": no null pointers, no dangling pointers, no buffer overflows.",[35,48,49,52],{},[23,50,51],{},"Fearless concurrency",": the compiler prevents data races.",[35,54,55,58],{},[23,56,57],{},"Zero-cost abstractions",": iterators, traits, generics compile down to the same machine code you'd write by hand.",[35,60,61,64],{},[23,62,63],{},"Strong type system",": algebraic data types (enums), pattern matching, traits.",[35,66,67,70,71,75,76,79,80,83,84,87,88,91],{},[23,68,69],{},"Great tooling",": ",[72,73,74],"code",{},"cargo"," (build\u002Fpackage), ",[72,77,78],{},"rustfmt"," (formatting), ",[72,81,82],{},"clippy"," (lints), ",[72,85,86],{},"rustdoc"," (docs), ",[72,89,90],{},"rust-analyzer"," (IDE).",[14,93,95],{"id":94},"the-compile-time-vs-runtime-tradeoff","The Compile-Time vs Runtime Tradeoff",[19,97,98],{},"Rust moves correctness checks to compile time. A program that compiles is far more likely to \"just work\" than in most languages. The cost: longer compile times and a steeper learning curve (especially ownership\u002Flifetimes).",[14,100,102],{"id":101},"installing-rust-rustup","Installing Rust (rustup)",[19,104,105,108],{},[72,106,107],{},"rustup"," is the official toolchain manager.",[110,111,113],"code-wrapper",{"language":112},"bash",[114,115,119],"pre",{"className":116,"code":117,"language":112,"meta":118,"style":118},"language-bash shiki shiki-themes github-light github-dark","# macOS \u002F Linux\ncurl --proto '=https' --tlsv1.2 -sSf https:\u002F\u002Fsh.rustup.rs | sh\n\n# Windows: download rustup-init.exe from https:\u002F\u002Frustup.rs\n","",[72,120,121,130,161,168],{"__ignoreMap":118},[122,123,126],"span",{"class":124,"line":125},"line",1,[122,127,129],{"class":128},"sdCPZ","# macOS \u002F Linux\n",[122,131,133,137,141,145,148,151,154,158],{"class":124,"line":132},2,[122,134,136],{"class":135},"sIsaT","curl",[122,138,140],{"class":139},"snvgF"," --proto",[122,142,144],{"class":143},"sJ6F3"," '=https'",[122,146,147],{"class":139}," --tlsv1.2",[122,149,150],{"class":139}," -sSf",[122,152,153],{"class":143}," https:\u002F\u002Fsh.rustup.rs",[122,155,157],{"class":156},"svdQ7"," |",[122,159,160],{"class":135}," sh\n",[122,162,164],{"class":124,"line":163},3,[122,165,167],{"emptyLinePlaceholder":166},true,"\n",[122,169,171],{"class":124,"line":170},4,[122,172,173],{"class":128},"# Windows: download rustup-init.exe from https:\u002F\u002Frustup.rs\n",[19,175,176],{},"Verify:",[110,178,179],{"language":112},[114,180,182],{"className":116,"code":181,"language":112,"meta":118,"style":118},"rustc --version\ncargo --version\nrustup --version\n",[72,183,184,192,198],{"__ignoreMap":118},[122,185,186,189],{"class":124,"line":125},[122,187,188],{"class":135},"rustc",[122,190,191],{"class":139}," --version\n",[122,193,194,196],{"class":124,"line":132},[122,195,74],{"class":135},[122,197,191],{"class":139},[122,199,200,202],{"class":124,"line":163},[122,201,107],{"class":135},[122,203,191],{"class":139},[205,206,208],"h3",{"id":207},"toolchain-components","Toolchain Components",[32,210,211,217,223],{},[35,212,213,216],{},[72,214,215],{},"stable"," — default, released every 6 weeks.",[35,218,219,222],{},[72,220,221],{},"beta"," — next stable candidate.",[35,224,225,228],{},[72,226,227],{},"nightly"," — unstable features (e.g., some macros, inline assembly).",[110,230,231],{"language":112},[114,232,234],{"className":116,"code":233,"language":112,"meta":118,"style":118},"rustup install stable\nrustup install nightly\nrustup default stable\nrustup component add rustfmt clippy rust-src rust-analyzer\nrustup target add wasm32-unknown-unknown   # cross-compile to WebAssembly\n",[72,235,236,246,255,264,286],{"__ignoreMap":118},[122,237,238,240,243],{"class":124,"line":125},[122,239,107],{"class":135},[122,241,242],{"class":143}," install",[122,244,245],{"class":143}," stable\n",[122,247,248,250,252],{"class":124,"line":132},[122,249,107],{"class":135},[122,251,242],{"class":143},[122,253,254],{"class":143}," nightly\n",[122,256,257,259,262],{"class":124,"line":163},[122,258,107],{"class":135},[122,260,261],{"class":143}," default",[122,263,245],{"class":143},[122,265,266,268,271,274,277,280,283],{"class":124,"line":170},[122,267,107],{"class":135},[122,269,270],{"class":143}," component",[122,272,273],{"class":143}," add",[122,275,276],{"class":143}," rustfmt",[122,278,279],{"class":143}," clippy",[122,281,282],{"class":143}," rust-src",[122,284,285],{"class":143}," rust-analyzer\n",[122,287,289,291,294,296,299],{"class":124,"line":288},5,[122,290,107],{"class":135},[122,292,293],{"class":143}," target",[122,295,273],{"class":143},[122,297,298],{"class":143}," wasm32-unknown-unknown",[122,300,301],{"class":128},"   # cross-compile to WebAssembly\n",[205,303,305],{"id":304},"editions","Editions",[19,307,308,309,312],{},"Editions (2015, 2018, 2021, 2024) are opt-in language evolutions. Set in ",[72,310,311],{},"Cargo.toml",":",[110,314,316],{"language":315},"toml",[114,317,320],{"className":318,"code":319,"language":315,"meta":118,"style":118},"language-toml shiki shiki-themes github-light github-dark","[package]\nedition = \"2021\"\n",[72,321,322,327],{"__ignoreMap":118},[122,323,324],{"class":124,"line":125},[122,325,326],{},"[package]\n",[122,328,329],{"class":124,"line":132},[122,330,331],{},"edition = \"2021\"\n",[19,333,334,335,339,340,343,344,347,348,351,352,355],{},"Code from older editions keeps compiling; editions are about how the ",[336,337,338],"em",{},"parser"," sees your code, not the runtime behavior. Key 2021 changes: ",[72,341,342],{},"IntoIterator"," for arrays, disjoint closure captures, ",[72,345,346],{},"panic"," macros consistency. Edition 2024 adds ",[72,349,350],{},"unsafe"," attributes on extern blocks, ",[72,353,354],{},"gen"," keyword reservation, etc.",[14,357,359],{"id":358},"the-cargo-build-pipeline","The Cargo Build Pipeline",[114,361,366],{"className":362,"code":364,"language":365},[363],"language-text","cargo new my_project      # scaffolds a binary crate\ncargo new my_lib --lib    # scaffolds a library crate\ncargo build               # debug build -> target\u002Fdebug\ncargo build --release     # optimized build -> target\u002Frelease (O3-ish)\ncargo run                 # build + run binary\ncargo check               # type-check without codegen (fast feedback)\ncargo test                # run tests\ncargo doc --open          # generate & open docs\ncargo fmt                 # format code\ncargo clippy              # run lints\ncargo update             # update deps in Cargo.lock\ncargo tree               # print dependency tree\ncargo bench              # run benchmarks (requires nightly or criterion)\n","text",[72,367,364],{"__ignoreMap":118},[205,369,371],{"id":370},"profile-customization","Profile customization",[110,373,374],{"language":315},[114,375,377],{"className":318,"code":376,"language":315,"meta":118,"style":118},"# Cargo.toml\n[profile.release]\nopt-level = 3\nlto = \"fat\"          # link-time optimization across crates\ncodegen-units = 1    # better optimization, slower compile\nstrip = true         # strip debug symbols\npanic = \"abort\"      # smaller binary, no unwinding\n",[72,378,379,384,389,394,399,404,410],{"__ignoreMap":118},[122,380,381],{"class":124,"line":125},[122,382,383],{},"# Cargo.toml\n",[122,385,386],{"class":124,"line":132},[122,387,388],{},"[profile.release]\n",[122,390,391],{"class":124,"line":163},[122,392,393],{},"opt-level = 3\n",[122,395,396],{"class":124,"line":170},[122,397,398],{},"lto = \"fat\"          # link-time optimization across crates\n",[122,400,401],{"class":124,"line":288},[122,402,403],{},"codegen-units = 1    # better optimization, slower compile\n",[122,405,407],{"class":124,"line":406},6,[122,408,409],{},"strip = true         # strip debug symbols\n",[122,411,413],{"class":124,"line":412},7,[122,414,415],{},"panic = \"abort\"      # smaller binary, no unwinding\n",[14,417,419],{"id":418},"project-layout-conventions","Project Layout Conventions",[114,421,424],{"className":422,"code":423,"language":365},[363],"my_project\u002F\n├── Cargo.toml\n├── Cargo.lock          # binary: commit it; library: usually commit too\n├── src\u002F\n│   ├── main.rs         # binary crate root\n│   ├── lib.rs          # library crate root\n│   └── bin\u002F\n│       └── extra.rs    # additional binary target\n├── tests\u002F              # integration tests\n│   └── integration_test.rs\n├── benches\u002F\n│   └── my_bench.rs\n└── examples\u002F\n    └── example.rs\n",[72,425,423],{"__ignoreMap":118},[14,427,429],{"id":428},"edge-cases-gotchas","Edge Cases & Gotchas",[32,431,432,438,451,465,474,487,497],{},[35,433,434,437],{},[23,435,436],{},"Cargo.lock",": commit it for binaries to ensure reproducible builds. For libraries it's debated; the official guidance is to commit it too, but it's not required.",[35,439,440,446,447,450],{},[23,441,442,445],{},[72,443,444],{},"cargo check"," is your friend",": during development it's 10x faster than ",[72,448,449],{},"build",".",[35,452,453,457,458,461,462,450],{},[23,454,455],{},[72,456,90],{}," needs ",[72,459,460],{},"rust-src"," to show stdlib source — install it via ",[72,463,464],{},"rustup component add rust-src",[35,466,467,470,471,450],{},[23,468,469],{},"macOS linkers",": if you hit linker errors, install Xcode Command Line Tools: ",[72,472,473],{},"xcode-select --install",[35,475,476,479,480,483,484,486],{},[23,477,478],{},"MSRV"," (Minimum Supported Rust Version): set with ",[72,481,482],{},"rust-version"," in ",[72,485,311],{},"; CI should pin to that version.",[35,488,489,492,493,496],{},[23,490,491],{},"Incremental compilation",": on by default in dev; can occasionally produce stale errors — ",[72,494,495],{},"cargo clean"," fixes it.",[35,498,499,504,505,508],{},[23,500,501],{},[72,502,503],{},"~\u002F.cargo\u002Fbin"," must be on your ",[72,506,507],{},"PATH"," (rustup installer adds it to your shell profile).",[14,510,512],{"id":511},"recommended-environment-vs-code","Recommended Environment (VS Code)",[19,514,515,516,518],{},"Install the ",[23,517,90],{}," extension (NOT the legacy \"Rust\" extension). Enable:",[32,520,521,526,532],{},[35,522,523],{},[72,524,525],{},"rust-analyzer.check.command = \"clippy\"",[35,527,528,531],{},[72,529,530],{},"rust-analyzer.inlayHints"," for type\u002Fchaining hints",[35,533,534,535],{},"Format on save with ",[72,536,78],{},[14,538,540],{"id":539},"summary","Summary",[19,542,543,544,546],{},"You now have the toolchain and understand the build lifecycle. Next: writing your first program and reading ",[72,545,311],{}," semantics.",[548,549,550],"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 .sIsaT, html code.shiki .sIsaT{--shiki-default:#6F42C1;--shiki-github-dark:#B392F0}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}html pre.shiki code .svdQ7, html code.shiki .svdQ7{--shiki-default:#D73A49;--shiki-github-dark:#F97583}",{"title":118,"searchDepth":132,"depth":132,"links":552},[553,554,555,559,562,563,564,565],{"id":16,"depth":132,"text":17},{"id":94,"depth":132,"text":95},{"id":101,"depth":132,"text":102,"children":556},[557,558],{"id":207,"depth":163,"text":208},{"id":304,"depth":163,"text":305},{"id":358,"depth":132,"text":359,"children":560},[561],{"id":370,"depth":163,"text":371},{"id":418,"depth":132,"text":419},{"id":428,"depth":132,"text":429},{"id":511,"depth":132,"text":512},{"id":539,"depth":132,"text":540},"md",{},"\u002Frust\u002F01-introduction-and-setup",{"title":5,"description":118},"rust\u002F01-introduction-and-setup","zqWiOajZ7P8LUvmI2RhLCi3E2DKMNjIjuXMFZoGGuts",1785944092915]