Skip to content

Commit 12e26ae

Browse files
committed
PME on array_chunks::<0>
1 parent 7fa1908 commit 12e26ae

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/array_chunks.rs

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ pub struct ArrayChunks<I: Iterator, const N: usize> {
1313

1414
impl<I: Iterator, const N: usize> ArrayChunks<I, N> {
1515
pub(crate) fn new(iter: I) -> Self {
16+
const {
17+
assert!(N > 0);
18+
}
1619
// TODO should we use iter.fuse() instead? Otherwise remainder may behave strangely
1720
Self {
1821
iter,

src/lib.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -750,12 +750,11 @@ pub trait Itertools: Iterator {
750750
/// Use the method `.remainder()` to access leftover items in case
751751
/// the number of items yielded by the original iterator is not a multiple of `N`.
752752
///
753-
/// If `N` is 0, the resulting iterator will be equivalent to `repeat([])`, i.e.
754-
/// `next()` will always return `Some([])`.
753+
/// `N == 0` is a compile-time (but post-monomorphization) error.
755754
///
756755
/// See also the method [`.next_array()`](Itertools::next_array).
757756
///
758-
/// ```
757+
/// ```rust
759758
/// use itertools::Itertools;
760759
/// let mut v = Vec::new();
761760
/// for [a, b] in (1..5).array_chunks() {
@@ -779,12 +778,13 @@ pub trait Itertools: Iterator {
779778
///
780779
/// let it: ArrayChunks<Range<u32>, 3> = (1..7).array_chunks();
781780
/// itertools::assert_equal(it, vec![[1, 2, 3], [4, 5, 6]]);
781+
/// ```
782782
///
783-
/// let mut it = (1..3).array_chunks::<0>();
784-
/// assert_eq!(it.next(), Some([]));
785-
/// assert_eq!(it.next(), Some([]));
786-
/// // and so on for any further calls to `it.next()`
787-
/// itertools::assert_equal(it.remainder(), 1..3);
783+
/// ```compile_fail
784+
/// use itertools::Itertools;
785+
///
786+
/// let mut it = (1..5).array_chunks::<0>();
787+
/// assert_eq!(Some([]), it.next());
788788
/// ```
789789
#[cfg(feature = "use_alloc")]
790790
fn array_chunks<const N: usize>(self) -> ArrayChunks<Self, N>

0 commit comments

Comments
 (0)