Skip to content

Commit 5caec61

Browse files
Add missing links to Rc doc
1 parent daf8c1d commit 5caec61

File tree

1 file changed

+45
-43
lines changed

1 file changed

+45
-43
lines changed

Diff for: src/liballoc/rc.rs

+45-43
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,35 @@
1212

1313
//! Single-threaded reference-counting pointers.
1414
//!
15-
//! The type [`Rc<T>`][rc] provides shared ownership of a value of type `T`,
16-
//! allocated in the heap. Invoking [`clone`][clone] on `Rc` produces a new
17-
//! pointer to the same value in the heap. When the last `Rc` pointer to a
15+
//! The type [`Rc<T>`][`Rc`] provides shared ownership of a value of type `T`,
16+
//! allocated in the heap. Invoking [`clone()`][clone] on [`Rc`] produces a new
17+
//! pointer to the same value in the heap. When the last [`Rc`] pointer to a
1818
//! given value is destroyed, the pointed-to value is also destroyed.
1919
//!
2020
//! Shared references in Rust disallow mutation by default, and `Rc` is no
21-
//! exception. If you need to mutate through an `Rc`, use [`Cell`][cell] or
22-
//! [`RefCell`][refcell].
21+
//! exception. If you need to mutate through an [`Rc`], use [`Cell`] or
22+
//! [`RefCell`].
2323
//!
24-
//! `Rc` uses non-atomic reference counting. This means that overhead is very
25-
//! low, but an `Rc` cannot be sent between threads, and consequently `Rc`
24+
//! [`Rc`] uses non-atomic reference counting. This means that overhead is very
25+
//! low, but an [`Rc`] cannot be sent between threads, and consequently [`Rc`]
2626
//! does not implement [`Send`][send]. As a result, the Rust compiler
27-
//! will check *at compile time* that you are not sending `Rc`s between
27+
//! will check *at compile time* that you are not sending [`Rc`]s between
2828
//! threads. If you need multi-threaded, atomic reference counting, use
2929
//! [`sync::Arc`][arc].
3030
//!
31-
//! The [`downgrade`][downgrade] method can be used to create a non-owning
32-
//! [`Weak`][weak] pointer. A `Weak` pointer can be [`upgrade`][upgrade]d
33-
//! to an `Rc`, but this will return [`None`][option] if the value has
31+
//! The [`downgrade()`][downgrade] method can be used to create a non-owning
32+
//! [`Weak`] pointer. A [`Weak`] pointer can be [`upgrade`][upgrade]d
33+
//! to an [`Rc`], but this will return [`None`] if the value has
3434
//! already been dropped.
3535
//!
36-
//! A cycle between `Rc` pointers will never be deallocated. For this reason,
37-
//! `Weak` is used to break cycles. For example, a tree could have strong
38-
//! `Rc` pointers from parent nodes to children, and `Weak` pointers from
36+
//! A cycle between [`Rc`] pointers will never be deallocated. For this reason,
37+
//! [`Weak`] is used to break cycles. For example, a tree could have strong
38+
//! [`Rc`] pointers from parent nodes to children, and [`Weak`] pointers from
3939
//! children back to their parents.
4040
//!
41-
//! `Rc<T>` automatically dereferences to `T` (via the [`Deref`][deref] trait),
42-
//! so you can call `T`'s methods on a value of type `Rc<T>`. To avoid name
43-
//! clashes with `T`'s methods, the methods of `Rc<T>` itself are [associated
41+
//! `Rc<T>` automatically dereferences to `T` (via the [`Deref`] trait),
42+
//! so you can call `T`'s methods on a value of type [`Rc<T>`][`Rc`]. To avoid name
43+
//! clashes with `T`'s methods, the methods of [`Rc<T>`][`Rc`] itself are [associated
4444
//! functions][assoc], called using function-like syntax:
4545
//!
4646
//! ```
@@ -50,28 +50,15 @@
5050
//! Rc::downgrade(&my_rc);
5151
//! ```
5252
//!
53-
//! `Weak<T>` does not auto-dereference to `T`, because the value may have
53+
//! [`Weak<T>`][`Weak`] does not auto-dereference to `T`, because the value may have
5454
//! already been destroyed.
5555
//!
56-
//! [rc]: struct.Rc.html
57-
//! [weak]: struct.Weak.html
58-
//! [clone]: ../../std/clone/trait.Clone.html#tymethod.clone
59-
//! [cell]: ../../std/cell/struct.Cell.html
60-
//! [refcell]: ../../std/cell/struct.RefCell.html
61-
//! [send]: ../../std/marker/trait.Send.html
62-
//! [arc]: ../../std/sync/struct.Arc.html
63-
//! [deref]: ../../std/ops/trait.Deref.html
64-
//! [downgrade]: struct.Rc.html#method.downgrade
65-
//! [upgrade]: struct.Weak.html#method.upgrade
66-
//! [option]: ../../std/option/enum.Option.html
67-
//! [assoc]: ../../book/method-syntax.html#associated-functions
68-
//!
6956
//! # Examples
7057
//!
7158
//! Consider a scenario where a set of `Gadget`s are owned by a given `Owner`.
7259
//! We want to have our `Gadget`s point to their `Owner`. We can't do this with
7360
//! unique ownership, because more than one gadget may belong to the same
74-
//! `Owner`. `Rc` allows us to share an `Owner` between multiple `Gadget`s,
61+
//! `Owner`. [`Rc`] allows us to share an `Owner` between multiple `Gadget`s,
7562
//! and have the `Owner` remain allocated as long as any `Gadget` points at it.
7663
//!
7764
//! ```
@@ -127,20 +114,20 @@
127114
//! ```
128115
//!
129116
//! If our requirements change, and we also need to be able to traverse from
130-
//! `Owner` to `Gadget`, we will run into problems. An `Rc` pointer from `Owner`
117+
//! `Owner` to `Gadget`, we will run into problems. An [`Rc`] pointer from `Owner`
131118
//! to `Gadget` introduces a cycle between the values. This means that their
132119
//! reference counts can never reach 0, and the values will remain allocated
133-
//! forever: a memory leak. In order to get around this, we can use `Weak`
120+
//! forever: a memory leak. In order to get around this, we can use [`Weak`]
134121
//! pointers.
135122
//!
136123
//! Rust actually makes it somewhat difficult to produce this loop in the first
137124
//! place. In order to end up with two values that point at each other, one of
138-
//! them needs to be mutable. This is difficult because `Rc` enforces
125+
//! them needs to be mutable. This is difficult because [`Rc`] enforces
139126
//! memory safety by only giving out shared references to the value it wraps,
140127
//! and these don't allow direct mutation. We need to wrap the part of the
141-
//! value we wish to mutate in a [`RefCell`][refcell], which provides *interior
128+
//! value we wish to mutate in a [`RefCell`], which provides *interior
142129
//! mutability*: a method to achieve mutability through a shared reference.
143-
//! `RefCell` enforces Rust's borrowing rules at runtime.
130+
//! [`RefCell`] enforces Rust's borrowing rules at runtime.
144131
//!
145132
//! ```
146133
//! use std::rc::Rc;
@@ -214,6 +201,19 @@
214201
//! // Gadget Man, so he gets destroyed as well.
215202
//! }
216203
//! ```
204+
//!
205+
//! [`Rc`]: struct.Rc.html
206+
//! [`Weak`]: struct.Weak.html
207+
//! [clone]: ../../std/clone/trait.Clone.html#tymethod.clone
208+
//! [`Cell`]: ../../std/cell/struct.Cell.html
209+
//! [`RefCell`]: ../../std/cell/struct.RefCell.html
210+
//! [send]: ../../std/marker/trait.Send.html
211+
//! [arc]: ../../std/sync/struct.Arc.html
212+
//! [`Deref`]: ../../std/ops/trait.Deref.html
213+
//! [downgrade]: struct.Rc.html#method.downgrade
214+
//! [upgrade]: struct.Weak.html#method.upgrade
215+
//! [`None`]: ../../std/option/enum.Option.html#variant.None
216+
//! [assoc]: ../../book/method-syntax.html#associated-functions
217217
218218
#![stable(feature = "rust1", since = "1.0.0")]
219219

@@ -251,9 +251,11 @@ struct RcBox<T: ?Sized> {
251251
/// See the [module-level documentation](./index.html) for more details.
252252
///
253253
/// The inherent methods of `Rc` are all associated functions, which means
254-
/// that you have to call them as e.g. `Rc::get_mut(&value)` instead of
255-
/// `value.get_mut()`. This avoids conflicts with methods of the inner
254+
/// that you have to call them as e.g. [`Rc::get_mut(&value)`][get_mut] instead of
255+
/// `value.get_mut()`. This avoids conflicts with methods of the inner
256256
/// type `T`.
257+
///
258+
/// [get_mut]: #method.get_mut
257259
#[stable(feature = "rust1", since = "1.0.0")]
258260
pub struct Rc<T: ?Sized> {
259261
ptr: Shared<RcBox<T>>,
@@ -337,10 +339,10 @@ impl<T> Rc<T> {
337339
}
338340

339341
/// Checks whether [`Rc::try_unwrap`][try_unwrap] would return
340-
/// [`Ok`][result].
342+
/// [`Ok`].
341343
///
342344
/// [try_unwrap]: struct.Rc.html#method.try_unwrap
343-
/// [result]: ../../std/result/enum.Result.html
345+
/// [`Ok`]: ../../std/result/enum.Result.html#variant.Ok
344346
///
345347
/// # Examples
346348
///
@@ -543,14 +545,14 @@ impl<T: ?Sized> Rc<T> {
543545
/// Returns a mutable reference to the inner value, if there are
544546
/// no other `Rc` or [`Weak`][weak] pointers to the same value.
545547
///
546-
/// Returns [`None`][option] otherwise, because it is not safe to
548+
/// Returns [`None`] otherwise, because it is not safe to
547549
/// mutate a shared value.
548550
///
549551
/// See also [`make_mut`][make_mut], which will [`clone`][clone]
550552
/// the inner value when it's shared.
551553
///
552554
/// [weak]: struct.Weak.html
553-
/// [option]: ../../std/option/enum.Option.html
555+
/// [`None`]: ../../std/option/enum.Option.html#variant.None
554556
/// [make_mut]: struct.Rc.html#method.make_mut
555557
/// [clone]: ../../std/clone/trait.Clone.html#tymethod.clone
556558
///

0 commit comments

Comments
 (0)