Function lending_iterator::windows_mut
source · pub fn windows_mut<T, const WINDOW_SIZE: usize>(
slice: &mut [T]
) -> WindowsMut<&mut [T], WINDOW_SIZE> ⓘ
Expand description
Creates an impl LendingIterator
over the sliding windows
of a slice, with &mut
/ exclusive access over them (yields &mut [T]
slices).
This is thus “simply” the mut
counter-part of windows()
,
but for the mut
playing a key role w.r.t. semantics and borrows: indeed,
the different sliding windows may overlap! This goes against the
exclusivity of &mut
references, so the different windows cannot
coëxist!
This is something that the traditional Iterator
trait cannot express,
thence this LendingIterator
definition which can.
-
This is a free function version of the
.windows_mut()
method provided by the eponymous extension trait.That is, feel free to check out that extension method, since in practice it’s even more ergonomic to use.