Skip to content

Commit 6bede55

Browse files
committed
avoid const assert to keep msrv
1 parent 532758a commit 6bede55

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/arrays.rs

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

1414
impl<I: Iterator, const N: usize> Arrays<I, N> {
1515
pub(crate) fn new(iter: I) -> Self {
16-
const {
17-
assert!(N > 0);
18-
}
16+
assert_positive::<N>();
17+
1918
// TODO should we use iter.fuse() instead? Otherwise remainder may behave strangely
2019
Self {
2120
iter,
@@ -86,6 +85,22 @@ impl<I: Iterator, const N: usize> Iterator for Arrays<I, N> {
8685

8786
impl<I: ExactSizeIterator, const N: usize> ExactSizeIterator for Arrays<I, N> {}
8887

88+
/// Effectively assert!(N > 0) post-monomorphization
89+
fn assert_positive<const N: usize>() {
90+
trait StaticAssert<const N: usize> {
91+
const ASSERT: bool;
92+
}
93+
94+
impl<const N: usize> StaticAssert<N> for () {
95+
const ASSERT: bool = {
96+
assert!(N > 0);
97+
true
98+
};
99+
}
100+
101+
assert!(<() as StaticAssert<N>>::ASSERT);
102+
}
103+
89104
#[cfg(test)]
90105
mod tests {
91106
use crate::Itertools;

0 commit comments

Comments
 (0)