Skip to content

Commit f5b8238

Browse files
committed
Align smart pointer descriptions and links
We now avoid the `<T>` in the page title. We refer to `Rc` and `Arc` as reference-counted shared pointers that allow access to data from multiple places or threads.
1 parent 102d4a3 commit f5b8238

File tree

6 files changed

+27
-19
lines changed

6 files changed

+27
-19
lines changed

src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
- [Exercise: Builder Type](memory-management/exercise.md)
141141
- [Solution](memory-management/solution.md)
142142
- [Smart Pointers](smart-pointers.md)
143-
- [`Box<T>`](smart-pointers/box.md)
143+
- [`Box`](smart-pointers/box.md)
144144
- [`Rc`](smart-pointers/rc.md)
145145
- [Owned Trait Objects](smart-pointers/trait-objects.md)
146146
- [Exercise: Binary Tree](smart-pointers/exercise.md)

src/borrowing/interior-mutability.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ while still ensuring safety, typically by performing a runtime check.
1414

1515
## `RefCell`
1616

17+
A [`RefCell<T>`] gives you mutable access to a value behind a shared reference:
18+
1719
```rust,editable
1820
use std::cell::RefCell;
1921
@@ -36,9 +38,9 @@ fn main() {
3638

3739
## `Cell`
3840

39-
`Cell` wraps a value and allows getting or setting the value, even with a shared
40-
reference to the `Cell`. However, it does not allow any references to the value.
41-
Since there are no references, borrowing rules cannot be broken.
41+
[`Cell<T>`] wraps a `T` value. It allows getting or setting the value, even with
42+
a shared reference to the `Cell`. However, it does not allow any references to
43+
the value. Since there are no references, the borrowing rules cannot be broken.
4244

4345
```rust,editable
4446
use std::cell::Cell;
@@ -72,3 +74,6 @@ that safety, and `RefCell` and `Cell` are two of them.
7274
have its own cost.
7375

7476
</details>
77+
78+
[`Cell<T>`]: https://doc.rust-lang.org/std/cell/struct.Cell.html
79+
[`RefCell<T>`]: https://doc.rust-lang.org/std/cell/struct.RefCell.html

src/concurrency/shared-state/arc.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ minutes: 5
44

55
# `Arc`
66

7-
[`Arc<T>`][1] allows shared read-only access via `Arc::clone`:
7+
[`Arc<T>`] is a reference-counted shared pointer to `T`. Use this when you need
8+
to refer to the same data from multiple threads:
89

910
```rust,editable
1011
use std::sync::Arc;
@@ -26,18 +27,21 @@ fn main() {
2627
}
2728
```
2829

29-
[1]: https://doc.rust-lang.org/std/sync/struct.Arc.html
30-
3130
<details>
3231

33-
- `Arc` stands for "Atomic Reference Counted", a thread safe version of `Rc`
34-
that uses atomic operations.
32+
- `Arc` is short for "Atomically Reference Counted". It uses atomic
33+
(thread-safe) CPU instructions to maintain the reference count. `Arc` is a
34+
thread safe version of [`Rc`].
3535
- `Arc<T>` implements `Clone` whether or not `T` does. It implements `Send` and
3636
`Sync` if and only if `T` implements them both.
3737
- `Arc::clone()` has the cost of atomic operations that get executed, but after
3838
that the use of the `T` is free.
3939
- Beware of reference cycles, `Arc` does not use a garbage collector to detect
4040
them.
41-
- `std::sync::Weak` can help.
41+
- [`std::sync::Weak`] can help avoid reference cycles.
4242

4343
</details>
44+
45+
[`Arc<T>`]: https://doc.rust-lang.org/std/sync/struct.Arc.html
46+
[`Rc`]: ../../smart-pointers/rc.md
47+
[`std::sync::Weak`]: https://doc.rust-lang.org/std/sync/struct.Weak.html

src/concurrency/shared-state/mutex.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ minutes: 14
66

77
[`Mutex<T>`][1] ensures mutual exclusion _and_ allows mutable access to `T`
88
behind a read-only interface (another form of
9-
[interior mutability](../../borrowing/interior-mutability)):
9+
[interior mutability](../../borrowing/interior-mutability.md)):
1010

1111
```rust,editable
1212
use std::sync::Mutex;

src/smart-pointers/box.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
minutes: 8
33
---
44

5-
# `Box<T>`
5+
# `Box`
66

7-
[`Box`](https://doc.rust-lang.org/std/boxed/struct.Box.html) is an owned pointer
8-
to data on the heap:
7+
[`Box<T>`](https://doc.rust-lang.org/std/boxed/struct.Box.html) is an owned
8+
pointer to a `T` on the heap:
99

1010
```rust,editable
1111
fn main() {
@@ -28,8 +28,7 @@ fn main() {
2828
```
2929

3030
`Box<T>` implements `Deref<Target = T>`, which means that you can
31-
[call methods
32-
from `T` directly on a `Box<T>`](https://doc.rust-lang.org/std/ops/trait.Deref.html#more-on-deref-coercion).
31+
[call methods from `T` directly](https://doc.rust-lang.org/std/ops/trait.Deref.html#more-on-deref-coercion).
3332

3433
Recursive data types or data types with dynamic sizes need to use a `Box`:
3534

src/smart-pointers/rc.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ minutes: 5
44

55
# `Rc`
66

7-
[`Rc`][1] is a reference-counted shared pointer. Use this when you need to refer
8-
to the same data from multiple places:
7+
[`Rc<T>`][1] is a reference-counted shared pointer to `T`. Use this when you
8+
need to refer to the same data from multiple places:
99

1010
```rust,editable
1111
use std::rc::Rc;
@@ -25,7 +25,7 @@ fn main() {
2525

2626
[1]: https://doc.rust-lang.org/std/rc/struct.Rc.html
2727
[2]: ../concurrency/shared-state/arc.md
28-
[3]: https://doc.rust-lang.org/std/sync/struct.Mutex.html
28+
[3]: ../concurrency/shared-state/mutex.md
2929
[4]: https://doc.rust-lang.org/std/rc/struct.Weak.html
3030

3131
<details>

0 commit comments

Comments
 (0)