/// Parallel iterator over immutable non-overlapping chunks of a slice #[derive(Debug)] pubstruct ChunksExact<'data, T: Sync> {
chunk_size: usize,
slice: &'data [T],
rem: &'data [T],
}
impl<'data, T: Sync> ChunksExact<'data, T> { pub(super) fn new(chunk_size: usize, slice: &'data [T]) -> Self { let rem_len = slice.len() % chunk_size; let len = slice.len() - rem_len; let (slice, rem) = slice.split_at(len); Self {
chunk_size,
slice,
rem,
}
}
/// Return the remainder of the original slice that is not going to be /// returned by the iterator. The returned slice has at most `chunk_size-1` /// elements. pubfn remainder(&self) -> &'data [T] { self.rem
}
}
/// Return the remainder of the original slice that is not going to be /// returned by the iterator. The returned slice has at most `chunk_size-1` /// elements. /// /// Note that this has to consume `self` to return the original lifetime of /// the data, which prevents this from actually being used as a parallel /// iterator since that also consumes. This method is provided for parity /// with `std::iter::ChunksExactMut`, but consider calling `remainder()` or /// `take_remainder()` as alternatives. pubfn into_remainder(self) -> &'data mut [T] { self.rem
}
/// Return the remainder of the original slice that is not going to be /// returned by the iterator. The returned slice has at most `chunk_size-1` /// elements. /// /// Consider `take_remainder()` if you need access to the data with its /// original lifetime, rather than borrowing through `&mut self` here. pubfn remainder(&mutself) -> &mut [T] { self.rem
}
/// Return the remainder of the original slice that is not going to be /// returned by the iterator. The returned slice has at most `chunk_size-1` /// elements. Subsequent calls will return an empty slice. pubfn take_remainder(&mutself) -> &'data mut [T] {
std::mem::take(&mutself.rem)
}
}
impl<'data, T: Send + 'data> ParallelIterator for ChunksExactMut<'data, T> { type Item = &'data mut [T];
fn drive_unindexed<C>(self, consumer: C) -> C::Result where
C: UnindexedConsumer<Self::Item>,
{
bridge(self, consumer)
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.