|
11 | 11 | //! is no exception: you cannot generally obtain a mutable reference to
|
12 | 12 | //! something inside an [`Rc`]. If you need mutability, put a [`Cell`]
|
13 | 13 | //! or [`RefCell`] inside the [`Rc`]; see [an example of mutability
|
14 |
| -//! inside an Rc][mutability]. |
| 14 | +//! inside an `Rc`][mutability]. |
15 | 15 | //!
|
16 | 16 | //! [`Rc`] uses non-atomic reference counting. This means that overhead is very
|
17 | 17 | //! low, but an [`Rc`] cannot be sent between threads, and consequently [`Rc`]
|
|
35 | 35 | //! `Rc<T>` automatically dereferences to `T` (via the [`Deref`] trait),
|
36 | 36 | //! so you can call `T`'s methods on a value of type [`Rc<T>`][`Rc`]. To avoid name
|
37 | 37 | //! clashes with `T`'s methods, the methods of [`Rc<T>`][`Rc`] itself are associated
|
38 |
| -//! functions, called using function-like syntax: |
| 38 | +//! functions, called using [fully qualified syntax]: |
39 | 39 | //!
|
40 | 40 | //! ```
|
41 | 41 | //! use std::rc::Rc;
|
42 |
| -//! let my_rc = Rc::new(()); |
43 | 42 | //!
|
| 43 | +//! let my_rc = Rc::new(()); |
44 | 44 | //! Rc::downgrade(&my_rc);
|
45 | 45 | //! ```
|
46 | 46 | //!
|
| 47 | +//! `Rc<T>`'s implementations of traits like `Clone` may also be called using |
| 48 | +//! fully qualified syntax. Some people prefer to use fully qualified syntax, |
| 49 | +//! while others prefer using method-call syntax. |
| 50 | +//! |
| 51 | +//! ``` |
| 52 | +//! use std::rc::Rc; |
| 53 | +//! |
| 54 | +//! let rc = Rc::new(()); |
| 55 | +//! // Method-call syntax |
| 56 | +//! let rc2 = rc.clone(); |
| 57 | +//! // Fully qualified syntax |
| 58 | +//! let rc3 = Rc::clone(&rc); |
| 59 | +//! ``` |
| 60 | +//! |
47 | 61 | //! [`Weak<T>`][`Weak`] does not auto-dereference to `T`, because the inner value may have
|
48 | 62 | //! already been dropped.
|
49 | 63 | //!
|
|
54 | 68 | //!
|
55 | 69 | //! ```
|
56 | 70 | //! use std::rc::Rc;
|
| 71 | +//! |
57 | 72 | //! let foo = Rc::new(vec![1.0, 2.0, 3.0]);
|
58 | 73 | //! // The two syntaxes below are equivalent.
|
59 | 74 | //! let a = foo.clone();
|
|
218 | 233 | //! [`Cell`]: core::cell::Cell
|
219 | 234 | //! [`RefCell`]: core::cell::RefCell
|
220 | 235 | //! [send]: core::marker::Send
|
221 |
| -//! [arc]: ../../std/sync/struct.Arc.html |
| 236 | +//! [arc]: crate::sync::Arc |
222 | 237 | //! [`Deref`]: core::ops::Deref
|
223 | 238 | //! [downgrade]: Rc::downgrade
|
224 | 239 | //! [upgrade]: Weak::upgrade
|
@@ -272,10 +287,9 @@ struct RcBox<T: ?Sized> {
|
272 | 287 | ///
|
273 | 288 | /// The inherent methods of `Rc` are all associated functions, which means
|
274 | 289 | /// that you have to call them as e.g., [`Rc::get_mut(&mut value)`][get_mut] instead of
|
275 |
| -/// `value.get_mut()`. This avoids conflicts with methods of the inner |
276 |
| -/// type `T`. |
| 290 | +/// `value.get_mut()`. This avoids conflicts with methods of the inner type `T`. |
277 | 291 | ///
|
278 |
| -/// [get_mut]: #method.get_mut |
| 292 | +/// [get_mut]: Rc::get_mut |
279 | 293 | #[cfg_attr(not(test), rustc_diagnostic_item = "Rc")]
|
280 | 294 | #[stable(feature = "rust1", since = "1.0.0")]
|
281 | 295 | pub struct Rc<T: ?Sized> {
|
|
0 commit comments