Skip to content

Commit

Permalink
Implement IntoIterator for &Primes<N> (#27)
Browse files Browse the repository at this point in the history
* Impl IntoIter for &Primes<N>

* Bump version number

* Add IntoIter region
  • Loading branch information
JSorngard authored May 10, 2024
1 parent 02c024b commit 47112c9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
This file contains the changes to the crate since version 0.4.8.

# 0.5.1

- Implement `IntoIterator` for `&Primes<N>`.

# 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.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
12 changes: 12 additions & 0 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ impl<const N: usize> AsRef<[Underlying; N]> for Primes<N> {

// endregion: AsRef

// region: IntoIterator

impl<const N: usize> IntoIterator for Primes<N> {
type Item = <[Underlying; N] as IntoIterator>::Item;
type IntoIter = <[Underlying; N] as IntoIterator>::IntoIter;
Expand All @@ -375,6 +377,16 @@ impl<const N: usize> IntoIterator for Primes<N> {
}
}

impl<'a, const N: usize> IntoIterator for &'a Primes<N> {
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<const N: usize, T: PartialEq<[Underlying; N]>> PartialEq<T> for Primes<N> {
Expand Down

0 comments on commit 47112c9

Please sign in to comment.