Rust
Feature | Immutable Variable (let ) | Constants (const ) |
---|---|---|
Evaluation | Runtime | Compile-time |
Type | Optional (inferred) | Required |
Scope | Block-local | Global or local |
Use Case | Runtime values, immutable after assigned | Fixed 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.