Back to articles
What Rust Does Differently: A Beginner's Perspective

What Rust Does Differently: A Beginner's Perspective

via Dev.to WebdevYounes Merzouka

Rust makes a lot of interesting decisions about how things work — what you can and cannot do, and how you do certain things. Coming from a mostly web development background, three concepts in particular caught my attention as a beginner: Mutability, Ownership, and Handling Null. Mutability Rust variables are immutable by default. So code like this in JavaScript: let a = 0 ; a += 1 ; ...wouldn't work in Rust: let a = 0 ; a += 1 ; // compiler error To mutate a variable, you need to add the mut keyword: let mut a = 0 ; a += 1 ; The reason is safety. This mechanism forces you to explicitly opt into mutability, which makes your code more deterministic and avoids problems — especially with concurrency, where two threads might otherwise modify the same variable without you realising it. Mutable References One thing that tripped me up early on was mutable references. Suppose we want to read from stdin : let mut s = String :: new (); io :: stdin () .read_line ( & s ); // passing a reference to

Continue reading on Dev.to Webdev

Opens in a new tab

Read Full Article
3 views

Related Articles