You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/doc/rust.md
+12-57Lines changed: 12 additions & 57 deletions
Original file line number
Diff line number
Diff line change
@@ -2426,9 +2426,9 @@ before the expression they apply to.
2426
2426
: Logical negation. On the boolean type, this flips between `true` and
2427
2427
`false`. On integer types, this inverts the individual bits in the
2428
2428
two's complement representation of the value.
2429
-
`@` and `~`
2429
+
`~`
2430
2430
: [Boxing](#pointer-types) operators. Allocate a box to hold the value they are applied to,
2431
-
and store the value in it. `@` creates a managed box, whereas `~` creates an owned box.
2431
+
and store the value in it. `~` creates an owned box.
2432
2432
`&`
2433
2433
: Borrow operator. Returns a reference, pointing to its operand.
2434
2434
The operand of a borrow is statically proven to outlive the resulting pointer.
@@ -3203,16 +3203,6 @@ All pointers in Rust are explicit first-class values.
3203
3203
They can be copied, stored into data structures, and returned from functions.
3204
3204
There are four varieties of pointer in Rust:
3205
3205
3206
-
Managed pointers (`@`)
3207
-
: These point to managed heap allocations (or "boxes") in the task-local, managed heap.
3208
-
Managed pointers are written `@content`,
3209
-
for example `@int` means a managed pointer to a managed box containing an integer.
3210
-
Copying a managed pointer is a "shallow" operation:
3211
-
it involves only copying the pointer itself
3212
-
(as well as any reference-count or GC-barriers required by the managed heap).
3213
-
Dropping a managed pointer does not necessarily release the box it points to;
3214
-
the lifecycles of managed boxes are subject to an unspecified garbage collection algorithm.
3215
-
3216
3206
Owning pointers (`~`)
3217
3207
: These point to owned heap allocations (or "boxes") in the shared, inter-task heap.
3218
3208
Each owned box has a single owning pointer; pointer and pointee retain a 1:1 relationship at all times.
@@ -3521,63 +3511,28 @@ state. Subsequent statements within a function may or may not initialize the
3521
3511
local variables. Local variables can be used only after they have been
3522
3512
initialized; this is enforced by the compiler.
3523
3513
3524
-
### Memory boxes
3525
-
3526
-
A _box_ is a reference to a heap allocation holding another value. There
3527
-
are two kinds of boxes: *managed boxes* and *owned boxes*.
3528
-
3529
-
A _managed box_ type or value is constructed by the prefix *at* sigil `@`.
3530
-
3531
-
An _owned box_ type or value is constructed by the prefix *tilde* sigil `~`.
3514
+
### Owned boxes
3532
3515
3533
-
Multiple managed box values can point to the same heap allocation; copying a
3534
-
managed box value makes a shallow copy of the pointer (optionally incrementing
3535
-
a reference count, if the managed box is implemented through
3536
-
reference-counting).
3516
+
An _owned box_ is a reference to a heap allocation holding another value, which is constructed
3517
+
by the prefix *tilde* sigil `~`
3537
3518
3538
-
Owned box values exist in 1:1 correspondence with their heap allocation.
3539
-
3540
-
An example of constructing one managed box type and value, and one owned box
3541
-
type and value:
3519
+
An example of an owned box type and value:
3542
3520
3543
3521
~~~~
3544
-
let x: @int = @10;
3545
3522
let x: ~int = ~10;
3546
3523
~~~~
3547
3524
3548
-
Some operations (such as field selection) implicitly dereference boxes. An
3549
-
example of an _implicit dereference_ operation performed on box values:
3525
+
Owned box values exist in 1:1 correspondence with their heap allocation
3526
+
copying an owned box value makes a shallow copy of the pointer
3527
+
Rust will consider a shallow copy of an owned box to move ownership of the value. After a value has been moved, the source location cannot be used unless it is reinitialized.
3550
3528
3551
3529
~~~~
3552
-
struct Foo { y: int }
3553
-
let x = @Foo{y: 10};
3554
-
assert!(x.y == 10);
3555
-
~~~~
3556
-
3557
-
Other operations act on box values as single-word-sized address values. For
3558
-
these operations, to access the value held in the box requires an explicit
3559
-
dereference of the box value. Explicitly dereferencing a box is indicated with
3560
-
the unary *star* operator `*`. Examples of such _explicit dereference_
3561
-
operations are:
3562
-
3563
-
* copying box values (`x = y`)
3564
-
* passing box values to functions (`f(x,y)`)
3565
-
3566
-
An example of an explicit-dereference operation performed on box values:
3567
-
3530
+
let x: ~int = ~10;
3531
+
let y = x;
3532
+
// attempting to use `x` will result in an error here
0 commit comments