@@ -2510,27 +2510,53 @@ tuple of arguments.
2510
2510
Enumerated types cannot be denoted * structurally* as types, but must be
2511
2511
denoted by named reference to an [ * enumeration* item] ( #enumerations ) .
2512
2512
2513
- ### Box types
2514
-
2515
- Box types are represented as pointers. There are three flavours of
2516
- pointers:
2517
-
2518
- Shared boxes (` @ ` )
2519
- : These are reference-counted boxes. Their type is written
2520
- ` @content ` , for example ` @int ` means a shared box containing an
2521
- integer. Copying a value of such a type means copying the pointer
2522
- and increasing the reference count.
2523
-
2524
- Unique boxes (` ~ ` )
2525
- : Unique boxes have only a single owner, and are freed when their
2526
- owner releases them. They are written ` ~content ` . Copying a
2527
- unique box involves copying the contents into a new box.
2528
-
2529
- Unsafe pointers (` * ` )
2530
- : Unsafe pointers are pointers without safety guarantees or
2531
- language-enforced semantics. Their type is written ` *content ` .
2532
- They can be copied and dropped freely. Dereferencing an unsafe
2533
- pointer is part of the unsafe sub-dialect of Rust.
2513
+ ### Pointer types
2514
+
2515
+ All pointers in Rust are explicit first-class values.
2516
+ They can be copied, stored into data structures, and returned from functions.
2517
+ There are four varieties of pointer in Rust:
2518
+
2519
+ Managed pointers (` @ ` )
2520
+ : These point to managed heap allocations (or "boxes") in the task-local, managed heap.
2521
+ Managed pointers are written ` @content ` ,
2522
+ for example ` @int ` means a managed pointer to a managed box containing an integer.
2523
+ Copying a managed pointer is a "shallow" operation:
2524
+ it involves only copying the pointer itself
2525
+ (as well as any reference-count or GC-barriers required by the managed heap).
2526
+ Dropping a managed pointer does not necessarily release the box it points to;
2527
+ the lifecycles of managed boxes are subject to an unspecified garbage collection algorithm.
2528
+
2529
+ Owning pointers (` ~ ` )
2530
+ : These point to owned heap allocations (or "boxes") in the shared, inter-task heap.
2531
+ Each owned box has a single owning pointer; pointer and pointee retain a 1:1 relationship at all times.
2532
+ Owning pointers are written ` ~content ` ,
2533
+ for example ` ~int ` means an owning pointer to an owned box containing an integer.
2534
+ Copying an owned box is a "deep" operation:
2535
+ it involves allocating a new owned box and copying the contents of the old box into the new box.
2536
+ Releasing an owning pointer immediately releases its corresponding owned box.
2537
+
2538
+ Borrowed pointers (` & ` )
2539
+ : These point to memory _ owned by some other value_ .
2540
+ Borrowed pointers arise by (automatic) conversion from owning pointers, managed pointers,
2541
+ or by applying the borrowing operator ` & ` to some other value,
2542
+ including [ lvalues, rvalues or temporaries] ( #lvalues-rvalues-and-temporaries ) .
2543
+ Borrowed pointers are written ` &content ` , or in some cases ` &f/content ` for some lifetime-variable ` f ` ,
2544
+ for example ` &int ` means a borrowed pointer to an integer.
2545
+ Copying a borrowed pointer is a "shallow" operation:
2546
+ it involves only copying the pointer itself.
2547
+ Releasing a borrowed pointer typically has no effect on the value it points to,
2548
+ with the exception of temporary values,
2549
+ which are released when the last borrowed pointer to them is released.
2550
+
2551
+ Raw pointers (` * ` )
2552
+ : Raw pointers are pointers without safety or liveness guarantees.
2553
+ Raw pointers are written ` *content ` ,
2554
+ for example ` *int ` means a raw pointer to an integer.
2555
+ Copying or dropping a raw pointer is has no effect on the lifecycle of any other value.
2556
+ Dereferencing a raw pointer or converting it to any other pointer type is an [ ` unsafe ` operation] ( #unsafe-functions ) .
2557
+ Raw pointers are generally discouraged in Rust code;
2558
+ they exist to support interoperability with foreign code,
2559
+ and writing performance-critical or low-level functions.
2534
2560
2535
2561
### Function types
2536
2562
0 commit comments