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 {