Post

Rust

FeatureImmutable Variable (let)Constants (const)
EvaluationRuntimeCompile-time
TypeOptional (inferred)Required
ScopeBlock-localGlobal or local
Use CaseRuntime values, immutable after assignedFixed values, known at compile time

Shadowing effectively creates a new variable with the same name as an existing one, allowing the reuse of the variable name while potentially altering its type or value.

1
2
let spaces = "    ";
let spaces = spaces.len();
This post is licensed under CC BY 4.0 by the author.