今日已更新 184 条资讯 | 累计 30228 条内容
关于我们

Vars and muts )ruff(

Tyr 2026年08月11日 05:43 0 次阅读 来源:Dev.to

Okay Okay, I've used the Rust book online and W3 schools mostly to learn most of what I know. Plus a video or two, but I can't focus on them as of well. Alright, first time putting this to text, but I'll try and explain the concepts, how I myself understand them. From Ch 3 of the Rust book. So in CH 3 it essentially focuses on variables )your x's, y's etc. etc.( and how variables in rust are by def not able to changed, "immutable" by the book. The gist of why is that it guarantees the variable isn't changed when it's not supposed to be or by another function. It also just serves like a safety blanket of sorts, say if you were to have a huge program. You use "let x = 5" you'll know that x = 5 EVERYWHERE. It won't change because the program won't run, you won't even get past the compiler if you try and change the value without saying it can change. This helps in stopping bugs from cropping up, specially since it's how malactors get in. helps debugging by knowing what can and can't flip a bit. Plus if you're building robust code, less stuff changing is better, cuz less stuff fails.. Like a car. fn main () { let x = 5 ; x = 20294 ; // you can't change this, it'll show as an error since you "x" isn't "mut" mutable, or changeable. } simple, right? Roast me if wrong. 08.10.26 -Tyr

本文内容来源于互联网,版权归原作者所有
查看原文