|
728 | 728 | //! "propagates" to this field or not. Pinning that propagates is also called "structural",
|
729 | 729 | //! because it follows the structure of the type.
|
730 | 730 | //!
|
731 |
| -//! The choice of whether to pin depends on how the type is being used. If [`unsafe`] code |
732 |
| -//! that consumes <code>[Pin]\<[&mut Struct][&mut]></code> also needs to take note of |
733 |
| -//! the address of the field itself, it may be evidence that that field is structurally |
734 |
| -//! pinned. Unfortunately, there are no hard-and-fast rules. |
| 731 | +//! This choice depends on what guarantees you need from the field for your [`unsafe`] code to work. |
| 732 | +//! If the field is itself address-sensitive, or participates in the parent struct's address |
| 733 | +//! sensitivity, it will need to be structurally pinned. |
| 734 | +//! |
| 735 | +//! A useful test is if [`unsafe`] code that consumes <code>[Pin]\<[&mut Struct][&mut]></code> |
| 736 | +//! also needs to take note of the address of the field itself, it may be evidence that that field |
| 737 | +//! is structurally pinned. Unfortunately, there are no hard-and-fast rules. |
735 | 738 | //!
|
736 | 739 | //! ### Choosing pinning *not to be* structural for `field`...
|
737 | 740 | //!
|
738 |
| -//! While counter-intuitive, it's actually the easier choice: if you do not expose a |
739 |
| -//! <code>[Pin]<[&mut] Field></code>, then no code must be written assuming that the field is |
740 |
| -//! pinned and so nothing can go wrong. So, if you decide that some field does not |
741 |
| -//! have structural pinning, all you have to ensure is that you never create pinning |
| 741 | +//! While counter-intuitive, it's often the easier choice: if you do not expose a |
| 742 | +//! <code>[Pin]<[&mut] Field></code>, you do not need to be careful about other code |
| 743 | +//! moving out of that field, you just have to ensure is that you never create pinning |
742 | 744 | //! reference to that field. This does of course also mean that if you decide a field does not
|
743 | 745 | //! have structural pinning, you must not write [`unsafe`] code that assumes (invalidly) that the
|
744 | 746 | //! field *is* structurally pinned!
|
|
0 commit comments