blob: ce10d66c4084b3cf3a1e9a8321c1a95be14b37f3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
|
[[Rust]]
It is basically redeclaring the same variable, but it can be redeclared with a **different type**. A immutable variable can also be shadowed.
Shadowing is undone when the scope ends, for example in a closure I can shadow a variable from the parent scope, but in the parent scope after the child scope ends we have the original value not the one from the child scope.
It is useful for reusing a name, ie:
```rust
let spaces = " ";
let spaces = spaces.len();
```
> the type of spaces changes from string to u32.
|