|
158 | 158 | //! is called *even if your type was previously pinned*! It is as if the
|
159 | 159 | //! compiler automatically called `get_unchecked_mut`.
|
160 | 160 | //!
|
161 |
| -//! This can never cause a problem in safe code because implementing a type that relies on pinning |
162 |
| -//! requires unsafe code, but be aware that deciding to make use of pinning |
163 |
| -//! in your type (for example by implementing some operation on `Pin<&[mut] Self>`) |
164 |
| -//! has consequences for your `Drop` implementation as well: if an element |
165 |
| -//! of your type could have been pinned, you must treat Drop as implicitly taking |
166 |
| -//! `Pin<&mut Self>`. |
| 161 | +//! This can never cause a problem in safe code because implementing a type that |
| 162 | +//! relies on pinning requires unsafe code, but be aware that deciding to make |
| 163 | +//! use of pinning in your type (for example by implementing some operation on |
| 164 | +//! `Pin<&Self>` or `Pin<&mut Self>`) has consequences for your `Drop` |
| 165 | +//! implementation as well: if an element of your type could have been pinned, |
| 166 | +//! you must treat Drop as implicitly taking `Pin<&mut Self>`. |
167 | 167 | //!
|
168 | 168 | //! In particular, if your type is `#[repr(packed)]`, the compiler will automatically
|
169 | 169 | //! move fields around to be able to drop them. As a consequence, you cannot use
|
|
173 | 173 | //!
|
174 | 174 | //! One interesting question arises when considering the interaction of pinning and
|
175 | 175 | //! the fields of a struct. When can a struct have a "pinning projection", i.e.,
|
176 |
| -//! an operation with type `fn(Pin<&[mut] Struct>) -> Pin<&[mut] Field>`? |
| 176 | +//! an operation with type `fn(Pin<&Struct>) -> Pin<&Field>`? |
177 | 177 | //! In a similar vein, when can a generic wrapper type (such as `Vec<T>`, `Box<T>`, or `RefCell<T>`)
|
178 |
| -//! have an operation with type `fn(Pin<&[mut] Wrapper<T>>) -> Pin<&[mut] T>`? |
| 178 | +//! have an operation with type `fn(Pin<&Wrapper<T>>) -> Pin<&T>`? |
179 | 179 | //!
|
180 | 180 | //! Having a pinning projection for some field means that pinning is "structural":
|
181 | 181 | //! when the wrapper is pinned, the field must be considered pinned, too.
|
182 |
| -//! After all, the pinning projection lets us get a `Pin<&[mut] Field>`. |
| 182 | +//! After all, the pinning projection lets us get a `Pin<&Field>`. |
183 | 183 | //!
|
184 | 184 | //! However, structural pinning comes with a few extra requirements, so not all
|
185 | 185 | //! wrappers can be structural and hence not all wrappers can offer pinning projections:
|
|
0 commit comments