Rust Variables
First session of Learning Rust, and you gotta start with the basics, right?
So let's discuss variables in Rust, some interesting things I've learned along the way, and some cursed ones (as someone who's mainly working with JavaScript/TypeScript these days)
First, you can declare variables, nothing too crazy so far.
However, you cannot reassign a variable, unless it's declared as a mut
(mutable), I guess this makes sense from a memory optimization point of view.
On the other hand, it's perfectly fine to redeclare a variable, even within the same scope.
And while you're redeclaring variables, why not also change their types? No biggy.
A last one to go, you're able to "assign result of control flow structures (if, else, etc.)" to a variable.
In the above, the value of team_size
is now "Medium"
, we also redeclared it and reassigned it with another type because life is too short to not do things like that.
So... variables in Rust are... interesting, a bit confusing for now, but I'll guess it'll start making sense at some point~
First published:
Last updated: