I\'m trying to implement an iterator which will yield prime numbers. I store already found prime numbers in a Vec
.
Here\'s my implementation:
Your PrimesIterator
type contains a non-mutable reference to a Vec<u64>
. You need to declare it as a mutable reference:
struct PrimesIterator<'a> {
primes: &'a mut Vec<u64>,
index: usize,
}
This will of course require you to also modify the iter()
function to make sure it passes a mutable reference:
impl Primes {
fn new() -> Primes {
Primes { primes: vec!(2, 3) }
}
fn iter(&mut self) -> PrimesIterator {
PrimesIterator { primes: &mut self.primes, index : 0 }
}
}