File tree 1 file changed +11
-4
lines changed
1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -3395,16 +3395,23 @@ a [temporary](#lvalues-rvalues-and-temporaries), or a local variable.
3395
3395
A _ local variable_ (or * stack-local* allocation) holds a value directly,
3396
3396
allocated within the stack's memory. The value is a part of the stack frame.
3397
3397
3398
- Local variables are immutable unless declared with ` let mut ` . The
3399
- ` mut ` keyword applies to all local variables declared within that
3400
- declaration (so ` let mut (x, y) = ... ` declares two mutable variables, ` x ` and
3401
- ` y ` ).
3398
+ Local variables are immutable unless declared otherwise like: ` let mut x = ... ` .
3402
3399
3403
3400
Function parameters are immutable unless declared with ` mut ` . The
3404
3401
` mut ` keyword applies only to the following parameter (so ` |mut x, y| `
3405
3402
and ` fn f(mut x: ~int, y: ~int) ` declare one mutable variable ` x ` and
3406
3403
one immutable variable ` y ` ).
3407
3404
3405
+ Methods that take either ` self ` or ` ~self ` can optionally place them in a
3406
+ mutable slot by prefixing them with ` mut ` (similar to regular arguments):
3407
+
3408
+ ~~~
3409
+ trait Changer {
3410
+ fn change(mut self) -> Self;
3411
+ fn modify(mut ~self) -> ~Self;
3412
+ }
3413
+ ~~~
3414
+
3408
3415
Local variables are not initialized when allocated; the entire frame worth of
3409
3416
local variables are allocated at once, on frame-entry, in an uninitialized
3410
3417
state. Subsequent statements within a function may or may not initialize the
You can’t perform that action at this time.
0 commit comments