Skip to content

Commit f78af18

Browse files
committed
tutorial: improve the managed boxes section
1 parent 85ed840 commit f78af18

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

doc/tutorial.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,20 @@ mutability. They do own the contained object, and mutability is defined by the
10531053
type of the shared box (`@` or `@mut`). An object containing a managed box is
10541054
not `Owned`, and can't be sent between tasks.
10551055

1056+
~~~~
1057+
let a = @5; // immutable
1058+
1059+
let mut b = @5; // mutable variable, immutable box
1060+
b = @10;
1061+
1062+
let c = @mut 5; // immutable variable, mutable box
1063+
*c = 10;
1064+
1065+
let mut d = @mut 5; // mutable variable, mutable box
1066+
*d += 5;
1067+
d = @mut 15;
1068+
~~~~
1069+
10561070
# Move semantics
10571071

10581072
Rust uses a shallow copy for parameter passing, assignment and returning values

0 commit comments

Comments
 (0)