Struct primal::Primes [] [src]

pub struct Primes {
    // some fields omitted

An iterator over all primes.

This will yield primes indefinitely (bits in usize permitting). If there is an known upper bound, sieving first with Sieve and using its primes_from method may be more efficient, especially if the bound is small.

This requires O(sqrt(p)) memory to yield prime p, where X is the maximum value of usize.


let count = primal::Primes::all().take_while(|p| *p < 1_000_000).count();
println!("{}", count);


impl Primes

fn all() -> Primes

The sequence 2, 3, 5, 7, 11, ....


// print the first 20 primes
for p in primal::Primes::all().take(20) {
    println!("{}", p);

Trait Implementations

impl Iterator for Primes

type Item = usize

fn next(&mut self) -> Option<usize>