mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
tutorial: improve the managed boxes section
This commit is contained in:
parent
85ed840e23
commit
f78af18127
@ -1053,6 +1053,20 @@ mutability. They do own the contained object, and mutability is defined by the
|
||||
type of the shared box (`@` or `@mut`). An object containing a managed box is
|
||||
not `Owned`, and can't be sent between tasks.
|
||||
|
||||
~~~~
|
||||
let a = @5; // immutable
|
||||
|
||||
let mut b = @5; // mutable variable, immutable box
|
||||
b = @10;
|
||||
|
||||
let c = @mut 5; // immutable variable, mutable box
|
||||
*c = 10;
|
||||
|
||||
let mut d = @mut 5; // mutable variable, mutable box
|
||||
*d += 5;
|
||||
d = @mut 15;
|
||||
~~~~
|
||||
|
||||
# Move semantics
|
||||
|
||||
Rust uses a shallow copy for parameter passing, assignment and returning values
|
||||
|
Loading…
Reference in New Issue
Block a user