1
1
# Variables
2
2
3
- A _ variable_ is a component of a stack frame, either a named function parameter,
3
+ A _ variable_ is a component of a stack frame. That component can be a named function parameter,
4
4
an anonymous [ temporary] ( expressions.html#lvalues-rvalues-and-temporaries ) , or a named local
5
5
variable.
6
6
7
7
A _ local variable_ (or * stack-local* allocation) holds a value directly,
8
8
allocated within the stack's memory. The value is a part of the stack frame.
9
9
10
- Local variables are immutable unless declared otherwise like : ` let mut x = ... ` .
10
+ Local variables are immutable unless declared otherwise. For example : ` let mut x = ... ` .
11
11
12
12
Function parameters are immutable unless declared with ` mut ` . The ` mut ` keyword
13
- applies only to the following parameter (so ` |mut x, y| ` and `fn f(mut x:
13
+ applies only to the following parameter. For example: ` |mut x, y| ` and `fn f(mut x:
14
14
Box<i32 >, y: Box<i32 >)` declare one mutable variable ` x` and one immutable
15
- variable ` y ` ) .
15
+ variable ` y ` .
16
16
17
17
Methods that take either ` self ` or ` Box<Self> ` can optionally place them in a
18
- mutable variable by prefixing them with ` mut ` (similar to regular arguments):
18
+ mutable variable by prefixing them with ` mut ` (similar to regular arguments). For example :
19
19
20
20
``` rust
21
21
trait Changer : Sized {
@@ -24,8 +24,8 @@ trait Changer: Sized {
24
24
}
25
25
```
26
26
27
- Local variables are not initialized when allocated; the entire frame worth of
28
- local variables are allocated at once , on frame-entry, in an uninitialized
27
+ Local variables are not initialized when allocated. Instead, the entire frame worth of
28
+ local variables are allocated, on frame-entry, in an uninitialized
29
29
state. Subsequent statements within a function may or may not initialize the
30
30
local variables. Local variables can be used only after they have been
31
31
initialized; this is enforced by the compiler.
0 commit comments