diff options
| author | Marijn Schouten <hkBst@users.noreply.github.com> | 2025-01-20 15:37:52 +0100 |
|---|---|---|
| committer | Marijn Schouten <mhkbst@gmail.com> | 2025-01-27 10:53:58 +0100 |
| commit | f630f7f410e38e55ed095a3ccc0131ddccbf6a3f (patch) | |
| tree | ef23cbf578c4951fc2971cdd0a26a3910346ea06 | |
| parent | b5741a36a897dd93936d31ea0c1688f1399a2e06 (diff) | |
| download | rust-f630f7f410e38e55ed095a3ccc0131ddccbf6a3f.tar.gz rust-f630f7f410e38e55ed095a3ccc0131ddccbf6a3f.zip | |
Clarify WindowsMut (Lending)Iterator
fixes 133628
| -rw-r--r-- | library/core/src/slice/mod.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index ba5746d0ade..1993a7491e1 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -1099,10 +1099,15 @@ impl<T> [T] { /// assert!(iter.next().is_none()); /// ``` /// - /// There's no `windows_mut`, as that existing would let safe code violate the - /// "only one `&mut` at a time to the same thing" rule. However, you can sometimes - /// use [`Cell::as_slice_of_cells`](crate::cell::Cell::as_slice_of_cells) in - /// conjunction with `windows` to accomplish something similar: + /// Because the [Iterator] trait cannot represent the required lifetimes, + /// there is no `windows_mut` analog to `windows`; + /// `[0,1,2].windows_mut(2).collect()` would violate [the rules of references] + /// (though a [LendingIterator] analog is possible). You can sometimes use + /// [`Cell::as_slice_of_cells`](crate::cell::Cell::as_slice_of_cells) in + /// conjunction with `windows` instead: + /// + /// [the rules of references]: https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html#the-rules-of-references + /// [LendingIterator]: https://blog.rust-lang.org/2022/10/28/gats-stabilization.html /// ``` /// use std::cell::Cell; /// |
