Skip to content

Commit d3915c5

Browse files
committed
Fix spacing in docs for core::pin by combining consequent code blocks using HTML-syntax.
1 parent 68ec332 commit d3915c5

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

Diff for: library/core/src/pin.rs

+23-23
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
//! By default, all types in Rust are movable. Rust allows passing all types by-value,
1717
//! and common smart-pointer types such as [`Box<T>`] and `&mut T` allow replacing and
1818
//! moving the values they contain: you can move out of a [`Box<T>`], or you can use [`mem::swap`].
19-
//! [`Pin<P>`] wraps a pointer type `P`, so [`Pin`]`<`[`Box`]`<T>>` functions much like a regular
20-
//! [`Box<T>`]: when a [`Pin`]`<`[`Box`]`<T>>` gets dropped, so do its contents, and the memory gets
21-
//! deallocated. Similarly, [`Pin`]`<&mut T>` is a lot like `&mut T`. However, [`Pin<P>`] does
19+
//! [`Pin<P>`] wraps a pointer type `P`, so <code>[Pin]<[Box]\<T>></code> functions much like a regular
20+
//! [`Box<T>`]: when a <code>[Pin]<[Box]\<T>></code> gets dropped, so do its contents, and the memory gets
21+
//! deallocated. Similarly, <code>[Pin]<&mut T></code> is a lot like `&mut T`. However, [`Pin<P>`] does
2222
//! not let clients actually obtain a [`Box<T>`] or `&mut T` to pinned data, which implies that you
2323
//! cannot use operations such as [`mem::swap`]:
2424
//!
@@ -40,8 +40,8 @@
4040
//!
4141
//! [`Pin<P>`] can be used to wrap any pointer type `P`, and as such it interacts with
4242
//! [`Deref`] and [`DerefMut`]. A [`Pin<P>`] where `P: Deref` should be considered
43-
//! as a "`P`-style pointer" to a pinned `P::Target` -- so, a [`Pin`]`<`[`Box`]`<T>>` is
44-
//! an owned pointer to a pinned `T`, and a [`Pin`]`<`[`Rc`]`<T>>` is a reference-counted
43+
//! as a "`P`-style pointer" to a pinned `P::Target` -- so, a <code>[Pin]<[Box]\<T>></code> is
44+
//! an owned pointer to a pinned `T`, and a <code>[Pin]<[Rc]\<T>></code> is a reference-counted
4545
//! pointer to a pinned `T`.
4646
//! For correctness, [`Pin<P>`] relies on the implementations of [`Deref`] and
4747
//! [`DerefMut`] not to move out of their `self` parameter, and only ever to
@@ -54,12 +54,12 @@
5454
//! [`bool`], [`i32`], and references) as well as types consisting solely of these
5555
//! types. Types that do not care about pinning implement the [`Unpin`]
5656
//! auto-trait, which cancels the effect of [`Pin<P>`]. For `T: Unpin`,
57-
//! [`Pin`]`<`[`Box`]`<T>>` and [`Box<T>`] function identically, as do [`Pin`]`<&mut T>` and
57+
//! <code>[Pin]<[Box]\<T>></code> and [`Box<T>`] function identically, as do <code>[Pin]<&mut T></code> and
5858
//! `&mut T`.
5959
//!
6060
//! Note that pinning and [`Unpin`] only affect the pointed-to type `P::Target`, not the pointer
6161
//! type `P` itself that got wrapped in [`Pin<P>`]. For example, whether or not [`Box<T>`] is
62-
//! [`Unpin`] has no effect on the behavior of [`Pin`]`<`[`Box`]`<T>>` (here, `T` is the
62+
//! [`Unpin`] has no effect on the behavior of <code>[Pin]<[Box]\<T>></code> (here, `T` is the
6363
//! pointed-to type).
6464
//!
6565
//! # Example: self-referential struct
@@ -158,7 +158,7 @@
158158
//!
159159
//! Notice that this guarantee does *not* mean that memory does not leak! It is still
160160
//! completely okay not ever to call [`drop`] on a pinned element (e.g., you can still
161-
//! call [`mem::forget`] on a [`Pin`]`<`[`Box`]`<T>>`). In the example of the doubly-linked
161+
//! call [`mem::forget`] on a <code>[Pin]<[Box]\<T>></code>). In the example of the doubly-linked
162162
//! list, that element would just stay in the list. However you may not free or reuse the storage
163163
//! *without calling [`drop`]*.
164164
//!
@@ -172,9 +172,9 @@
172172
//! This can never cause a problem in safe code because implementing a type that
173173
//! relies on pinning requires unsafe code, but be aware that deciding to make
174174
//! use of pinning in your type (for example by implementing some operation on
175-
//! [`Pin`]`<&Self>` or [`Pin`]`<&mut Self>`) has consequences for your [`Drop`]
175+
//! <code>[Pin]<&Self></code> or <code>[Pin]<&mut Self></code>) has consequences for your [`Drop`]
176176
//! implementation as well: if an element of your type could have been pinned,
177-
//! you must treat [`Drop`] as implicitly taking [`Pin`]`<&mut Self>`.
177+
//! you must treat [`Drop`] as implicitly taking <code>[Pin]<&mut Self></code>.
178178
//!
179179
//! For example, you could implement `Drop` as follows:
180180
//!
@@ -204,18 +204,18 @@
204204
//! # Projections and Structural Pinning
205205
//!
206206
//! When working with pinned structs, the question arises how one can access the
207-
//! fields of that struct in a method that takes just [`Pin`]`<&mut Struct>`.
207+
//! fields of that struct in a method that takes just <code>[Pin]<&mut Struct></code>.
208208
//! The usual approach is to write helper methods (so called *projections*)
209-
//! that turn [`Pin`]`<&mut Struct>` into a reference to the field, but what
210-
//! type should that reference have? Is it [`Pin`]`<&mut Field>` or `&mut Field`?
209+
//! that turn <code>[Pin]<&mut Struct></code> into a reference to the field, but what
210+
//! type should that reference have? Is it <code>[Pin]<&mut Field></code> or `&mut Field`?
211211
//! The same question arises with the fields of an `enum`, and also when considering
212212
//! container/wrapper types such as [`Vec<T>`], [`Box<T>`], or [`RefCell<T>`].
213213
//! (This question applies to both mutable and shared references, we just
214214
//! use the more common case of mutable references here for illustration.)
215215
//!
216216
//! It turns out that it is actually up to the author of the data structure
217217
//! to decide whether the pinned projection for a particular field turns
218-
//! [`Pin`]`<&mut Struct>` into [`Pin`]`<&mut Field>` or `&mut Field`. There are some
218+
//! <code>[Pin]<&mut Struct></code> into <code>[Pin]<&mut Field></code> or `&mut Field`. There are some
219219
//! constraints though, and the most important constraint is *consistency*:
220220
//! every field can be *either* projected to a pinned reference, *or* have
221221
//! pinning removed as part of the projection. If both are done for the same field,
@@ -230,12 +230,12 @@
230230
//! ## Pinning *is not* structural for `field`
231231
//!
232232
//! It may seem counter-intuitive that the field of a pinned struct might not be pinned,
233-
//! but that is actually the easiest choice: if a [`Pin`]`<&mut Field>` is never created,
233+
//! but that is actually the easiest choice: if a <code>[Pin]<&mut Field></code> is never created,
234234
//! nothing can go wrong! So, if you decide that some field does not have structural pinning,
235235
//! all you have to ensure is that you never create a pinned reference to that field.
236236
//!
237237
//! Fields without structural pinning may have a projection method that turns
238-
//! [`Pin`]`<&mut Struct>` into `&mut Field`:
238+
//! <code>[Pin]<&mut Struct></code> into `&mut Field`:
239239
//!
240240
//! ```rust,no_run
241241
//! # use std::pin::Pin;
@@ -251,14 +251,14 @@
251251
//!
252252
//! You may also `impl Unpin for Struct` *even if* the type of `field`
253253
//! is not [`Unpin`]. What that type thinks about pinning is not relevant
254-
//! when no [`Pin`]`<&mut Field>` is ever created.
254+
//! when no <code>[Pin]<&mut Field></code> is ever created.
255255
//!
256256
//! ## Pinning *is* structural for `field`
257257
//!
258258
//! The other option is to decide that pinning is "structural" for `field`,
259259
//! meaning that if the struct is pinned then so is the field.
260260
//!
261-
//! This allows writing a projection that creates a [`Pin`]`<&mut Field>`, thus
261+
//! This allows writing a projection that creates a <code>[Pin]<&mut Field></code>, thus
262262
//! witnessing that the field is pinned:
263263
//!
264264
//! ```rust,no_run
@@ -336,17 +336,17 @@
336336
//! and thus they do not offer pinning projections. This is why `Box<T>: Unpin` holds for all `T`.
337337
//! It makes sense to do this for pointer types, because moving the `Box<T>`
338338
//! does not actually move the `T`: the [`Box<T>`] can be freely movable (aka `Unpin`) even if
339-
//! the `T` is not. In fact, even [`Pin`]`<`[`Box`]`<T>>` and [`Pin`]`<&mut T>` are always
339+
//! the `T` is not. In fact, even <code>[Pin]<[Box]\<T>></code> and <code>[Pin]<&mut T></code> are always
340340
//! [`Unpin`] themselves, for the same reason: their contents (the `T`) are pinned, but the
341341
//! pointers themselves can be moved without moving the pinned data. For both [`Box<T>`] and
342-
//! [`Pin`]`<`[`Box`]`<T>>`, whether the content is pinned is entirely independent of whether the
342+
//! <code>[Pin]<[Box]\<T>></code>, whether the content is pinned is entirely independent of whether the
343343
//! pointer is pinned, meaning pinning is *not* structural.
344344
//!
345345
//! When implementing a [`Future`] combinator, you will usually need structural pinning
346346
//! for the nested futures, as you need to get pinned references to them to call [`poll`].
347347
//! But if your combinator contains any other data that does not need to be pinned,
348348
//! you can make those fields not structural and hence freely access them with a
349-
//! mutable reference even when you just have [`Pin`]`<&mut Self>` (such as in your own
349+
//! mutable reference even when you just have <code>[Pin]<&mut Self></code> (such as in your own
350350
//! [`poll`] implementation).
351351
//!
352352
//! [`Deref`]: crate::ops::Deref
@@ -356,10 +356,10 @@
356356
//! [`Box<T>`]: ../../std/boxed/struct.Box.html
357357
//! [`Vec<T>`]: ../../std/vec/struct.Vec.html
358358
//! [`Vec::set_len`]: ../../std/vec/struct.Vec.html#method.set_len
359-
//! [`Box`]: ../../std/boxed/struct.Box.html
359+
//! [Box]: ../../std/boxed/struct.Box.html
360360
//! [Vec::pop]: ../../std/vec/struct.Vec.html#method.pop
361361
//! [Vec::push]: ../../std/vec/struct.Vec.html#method.push
362-
//! [`Rc`]: ../../std/rc/struct.Rc.html
362+
//! [Rc]: ../../std/rc/struct.Rc.html
363363
//! [`RefCell<T>`]: crate::cell::RefCell
364364
//! [`drop`]: Drop::drop
365365
//! [`VecDeque<T>`]: ../../std/collections/struct.VecDeque.html

0 commit comments

Comments
 (0)