Vars and muts )ruff(

작성자

카테고리:

← 피드로
DEV Community · Tyr · 2026-08-11 개발(SW)

Tyr

Tyr

Posted on Aug 10 • Edited on Aug 12

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.
}  

Enter fullscreen mode Exit fullscreen mode

simple, right? Roast me if wrong.
08.10.26
-Tyr

원문에서 계속 ↗

추출 본문 · 출처: dev.to · https://dev.to/tyrkanzyka/vars-and-muts-ruff-2i1l

코멘트

답글 남기기