Clarify WindowsMut (Lending)Iterator

fixes 133628
This commit is contained in:
Marijn Schouten 2025-01-20 15:37:52 +01:00 committed by Marijn Schouten
parent b5741a36a8
commit f630f7f410

View File

@ -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;
///