From 47112c97b6d5e937c70b867b5c1ece5fd59f6f45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johanna=20S=C3=B6rng=C3=A5rd?= <44257381+JSorngard@users.noreply.github.com> Date: Fri, 10 May 2024 15:39:46 +0200 Subject: [PATCH] Implement `IntoIterator` for `&Primes` (#27) * Impl IntoIter for &Primes * Bump version number * Add IntoIter region --- CHANGELOG.md | 4 ++++ Cargo.toml | 2 +- src/cache.rs | 12 ++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fca3746..9346e50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ This file contains the changes to the crate since version 0.4.8. +# 0.5.1 + + - Implement `IntoIterator` for `&Primes`. + # 0.5.0 This version focuses on adding support for generating primes and sieving numbers in arbitrary ranges, instead of always having to start from 0. diff --git a/Cargo.toml b/Cargo.toml index c62dc23..1d325e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "const-primes" authors = ["Johanna Sörngård (jsorngard@gmail.com)"] -version = "0.5.0" +version = "0.5.1" edition = "2021" license = "MIT OR Apache-2.0" keywords = ["primes", "const"] diff --git a/src/cache.rs b/src/cache.rs index c499f94..3cb4423 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -366,6 +366,8 @@ impl AsRef<[Underlying; N]> for Primes { // endregion: AsRef +// region: IntoIterator + impl IntoIterator for Primes { type Item = <[Underlying; N] as IntoIterator>::Item; type IntoIter = <[Underlying; N] as IntoIterator>::IntoIter; @@ -375,6 +377,16 @@ impl IntoIterator for Primes { } } +impl<'a, const N: usize> IntoIterator for &'a Primes { + type IntoIter = <&'a [Underlying; N] as IntoIterator>::IntoIter; + type Item = <&'a [Underlying; N] as IntoIterator>::Item; + fn into_iter(self) -> Self::IntoIter { + self.primes.iter() + } +} + +// endregion: IntoIterator + // region: PartialEq impl> PartialEq for Primes {